Boost logo

Boost Users :

From: Will Bryant (will_at_[hidden])
Date: 2005-11-20 20:56:13


Merrill Cornish wrote:
> I am using Boost 1.33.0 with MinGW on Windows XP. I am using the following program_optins code to collect command line arguments:
>
[snip]
> * vm.count("graph_file") returns 0 regardless of whether there are positional argument(s).
>
> * specifying an -x, --xx, --xx=n option where "x" or "xx" is not included in desc.add_options() causes store() to not return (the program simply stops).
>
> Am I missing something?
>
As Liam points out, you need to use command_line_parser and
positional(...), which should resolve the first problem.

However, I've just hit the second problem in my own program, the help
formatter function is barfing. I'm using Visual Studio 2005 (still on
beta 2) on Windows XP and in fact I would have assumed this crash was a
bug in the beta, but if you're seeing similar crashage under MinGW too
then that seems unlikely.

Running it under the debugger shows an assertion failure in the string
iterator's += overloading, which is called by the -= overloading, which
is called by format_paragraph (line 377 in boost 1.33's
options_description.cpp):
                        string::const_iterator last_space =
                            
find(reverse_iterator<string::const_iterator>(line_end - 1),
                                 
reverse_iterator<string::const_iterator>(line_begin - 1),
                                 ' ')
                            .base();

(What's the deal with the reverse_iterator<string::const_iterator>s
there, is string::const_reverse_iterator nonstandard or unreliable?)

Looking at the options_description code, I believe the offending
calculation is "line_begin-1", which isn't valid since on the first
iteration line_begin will normally be equal to par.begin() (and so will
typically only work on string implementations where iterators are
pointers).

In other words, it appears to be an off-by-one bug in the iterator
constructions in format_paragraph.

Cheers,
Will

-- 
Will Bryant
http://carcino.gen.nz/
will_at_[hidden]
+64 21 655 443

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net