[program_options] PATCH: fix VC8 runtime assertion error in options_description.cpp

Hi, With regards to the following lines in the latest version (1.16) of program_options's options_description.cpp: 395: line_end = line_begin + line_length; 396: if (line_end > par_end) 397: { 398: line_end = par_end; 399: } Line 395 causes VC8 to throw a runtime assertion error when processing the last line of a multiline option description. This is because 'line_begin + line_length' will exceed the actual length of the string, and it seems VC8 is pretty intent on not letting that happen, despite the fact we correct it in following line. Following patch did the trick for me: --- options_description-1.16.cpp 2006-04-18 02:39:51.401147200 +0100 +++ options_description.cpp 2006-04-18 03:04:05.722358400 +0100 @@ -390,13 +390,13 @@ } } - string::const_iterator line_end; + string::const_iterator line_end = line_begin; + unsigned remaining = unsigned(distance(line_begin, par_end)); - line_end = line_begin + line_length; - if (line_end > par_end) - { - line_end = par_end; - } + // line_end will be determined by either the end of the + // current paragraph (remaining), or the current line + // length, which ever is less. + line_end += ((remaining < line_length) ? remaining : line_length); // prevent chopped words // Is line_end between two non-space characters?

Trent Nelson wrote:
Hi,
With regards to the following lines in the latest version (1.16) of program_options's options_description.cpp:
395: line_end = line_begin + line_length; 396: if (line_end > par_end) 397: { 398: line_end = par_end; 399: }
Line 395 causes VC8 to throw a runtime assertion error when processing the last line of a multiline option description. This is because 'line_begin + line_length' will exceed the actual length of the string, and it seems VC8 is pretty intent on not letting that happen, despite the fact we correct it in following line.
Hi Trent, can you provide me is a minimal example that reproduces this problem? I've tried multiline description just now, and did not get any assertion. I'd prefer to have a testcase for this bug before fixing it. Thanks in adavnce, Volodya
participants (2)
-
Trent Nelson
-
Vladimir Prus