Opened 16 years ago

Closed 15 years ago

#898 closed Bugs (fixed)

[program_options] improper guess

Reported by: alexis_wilke Owned by: Vladimir Prus
Milestone: Component: None
Version: None Severity: Showstopper
Keywords: Cc:

Description

I found a problem in the program_options when using the allow_guessing style (which is the default).

The option_description::match() function (boost_1_33_1/libs/program_options/src/options_description.cpp) checks option names approximatively only if the allow_guessing is turned on.

The match() function needs to return three values: definitively not this option, definitively this option or maybe this option. In the first case, you try the next option (see options_description::find_nothrow() in the same file). In the second case, you return with that very option. In the third case, you try the next options. If at the very end, you did not find a definitive option and you found more than 2 matching approximetly, then you generate the error (more than one approx. matched!). And if nothing matched, you generate that other error.

This is only partially fixed in Debian and I'm attaching that fix below. The problem in the Debian fix is that if the valid full definitive option is to be found AFTER two other partial options, it also breaks (duh! am I the only one to understand this logic?! it seems so simple!)

I did not understand the 1.34.0 yet and thus I did not see the fix there...

Change History (2)

comment:1 by alexis_wilke, 16 years ago

Logged In: YES 
user_id=554061
Originator: YES

Okay! I got it! You have tons of fixes in your CVS and no new tarball for years... Argh!

To finish up the fix, change the following:

            if (found != -1)
            {
                vector<string> alts;
                // FIXME: the use of 'key' here might not
                // be the best approach.
                alts.push_back(m_options[found]->key(name));
                alts.push_back(m_options[i]->key(name));
                boost::throw_exception(ambiguous_option(name, alts));
            }
            else
            {
                found = i;
            }


with this:

   if(found != -1) found = -2; else found = i;

then right after the loop:

   if(found == -2) throw ...

That lets people enter their options in whatever order
(especially if they have multiple tables of options like me!)

Thank you.

Note: I'm removing the attachment since that's what's in the CVS:

http://boost.cvs.sourceforge.net/boost/boost/libs/program_options/src/options_description.cpp?revision=1.16.2.3&view=markup


comment:2 by Vladimir Prus, 15 years ago

Resolution: Nonefixed
Severity: Showstopper
Status: assignedclosed

Fixed in CVS HEAD. I've used slightly different code solution, but thanks for the patch anyway!

Note: See TracTickets for help on using tickets.