[program_options] crash in VC++2005

In VC++2005 debug mode (Ctrl-F5), this little program aborts:
+++++++++++++ begin ++++++++++++++++++++++++
#include <iostream>
#include

n.torrey.pines wrote:
In VC++2005 debug mode (Ctrl-F5), this little program aborts:
+++++++++++++ begin ++++++++++++++++++++++++ #include <iostream> #include
int main(int argc, char * argv[]) { boost::program_options::options_description desc("Allowed options"); desc.add_options() ("some_option", "\ This option description SHOULD be long enough not to fit in one line"); std::cout << desc << '\n'; } ++++++++++++ end +++++++++++++++++++++++++++
The debug assertion failure message is:
File: C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\xstring Line: 173
Through multiple trials, I found that the error occurs if and only if the option description is long enough not to fit in one line in the window.
This is boost-1_33_1
Since I have no prior experience with program_options, perhaps I'm using it incorrectly?
This is a combination of somewhat sloppy code in the formatting code, and somewhat unreasonable runtime checking in VC++2005. This is supposed to be fixed in CVS, can you try it? - Volodya

Hi
I fooled around with the debugger a little, and it looks like
program_options decrements a string iterator that already points at
the beginning of a string.
string::const_iterator last_space =
find(reverse_iteratorstring::const_iterator(line_end - 1),
reverse_iteratorstring::const_iterator(line_begin - 1), ' ').base();
I'm assuming that this is the error (I haven't had a chance to look at
CVS yet). I'm no language lawyer, but I would think that such behavior
is undefined. Why is it unreasonable for VC++2005 to test for it?
I'm not an expert Boost user, and I need a stable version. Should I
just change (line - 1) to (line)+1 ?
On 2/23/07, Vladimir Prus
n.torrey.pines wrote:
In VC++2005 debug mode (Ctrl-F5), this little program aborts:
+++++++++++++ begin ++++++++++++++++++++++++ #include <iostream> #include
int main(int argc, char * argv[]) { boost::program_options::options_description desc("Allowed options"); desc.add_options() ("some_option", "\ This option description SHOULD be long enough not to fit in one line"); std::cout << desc << '\n'; } ++++++++++++ end +++++++++++++++++++++++++++
The debug assertion failure message is:
File: C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\xstring Line: 173
Through multiple trials, I found that the error occurs if and only if the option description is long enough not to fit in one line in the window.
This is boost-1_33_1
Since I have no prior experience with program_options, perhaps I'm using it incorrectly?
This is a combination of somewhat sloppy code in the formatting code, and somewhat unreasonable runtime checking in VC++2005. This is supposed to be fixed in CVS, can you try it?
- Volodya
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Torrey Pines wrote:
Hi
I fooled around with the debugger a little, and it looks like program_options decrements a string iterator that already points at the beginning of a string.
string::const_iterator last_space = find(reverse_iteratorstring::const_iterator(line_end - 1), reverse_iteratorstring::const_iterator(line_begin - 1), ' ').base();
I'm assuming that this is the error
It is.
(I haven't had a chance to look at CVS yet). I'm no language lawyer, but I would think that such behavior is undefined. Why is it unreasonable for VC++2005 to test for it?
Because the before the beginning iterator is never dereferenced, and for string, it's quite possible to decrement iterators any way you like. Checking done by VC++2005 might be ok from language lawyer point of view, but I don't see any real error that would prevent.
I'm not an expert Boost user, and I need a stable version. Should I just change (line - 1) to (line)+1 ?
I attach two patches that were committed to CVS to fix this problem. You might want to try to apply them manually to the version of options_description.cpp that you have. - Volodya
participants (3)
-
n.torrey.pines
-
Torrey Pines
-
Vladimir Prus