Re: [boost] [program_options] PATCH: fix VC8 runtime assertionerror in options_description.cpp

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.
The following option triggered the assertion error for me every time: desc.add_options() ("type,t", po::value<string>()->default_value("manual"), "startup type (\"auto\" or \"manual\") (--install only)")); If I reduced the description length such that it fit on a single line, the error went away for that particular option (only to crash on a different multiline option down the track). I was triggering the problem via '--help', which equated to 'cout << desc << endl;'. I've got a pretty vanilla VC++ Express 2005 installation, I haven't done anything out of the ordinary environment wise, which means all the new 'Standard C++ Library Security' features are enabled, so all the _SCL_SECURE_* macros are used. The following line:
395: line_end = line_begin + line_length;
Was being caught by the following macro on line 166 of 'C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring': _Myt& __CLR_OR_THIS_CALL operator+=(difference_type _Off) { // increment by integer if (this->_Mycont != _IGNORE_MYCONT) { _SCL_SECURE_VALIDATE(this->_Mycont != NULL); _SCL_SECURE_VALIDATE_RANGE( _Myptr + _Off <= (((_Mystring *)this->_Mycont)->_Myptr() + ((_Mystring *)this->_Mycont)->_Mysize) && _Myptr + _Off >= ((_Mystring *)this->_Mycont)->_Myptr()); } _Myptr += _Off; return (*this); } Which makes sense, as it's checking we don't assign past the end of our underlying string, which is exactly what line 395 of options_descriptions.cpp does in multiline conditions. If you can't reproduce the assertion in VC8 with the option description I listed above, I'd suggest putting a breakpoint on the _SCL_SECURE_VALIDATE_RANGE() macro above. If it's not being hit (which is what I'd expect), then something in your environment is disabling the _SCL_SECURE* stuff. If it is being hit, yet it's not throwing an assertion, then we have a much more interesting situation on our hands ;-) Regards, Trent. -- http://www.onresolve.com

Trent Nelson wrote:
I'd prefer to have a testcase for this bug before fixing it.
The following option triggered the assertion error for me every time:
desc.add_options() ("type,t", po::value<string>()->default_value("manual"), "startup type (\"auto\" or \"manual\") (--install only)"));
If I reduced the description length such that it fit on a single line, the error went away for that particular option (only to crash on a different multiline option down the track).
Thank you. I've comitted a new test that catches this problem, and a fix along the lines of what you've suggested. Thanks, and sorry for being slow with this issue.
Was being caught by the following macro on line 166 of 'C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring':
_Myt& __CLR_OR_THIS_CALL operator+=(difference_type _Off) { // increment by integer if (this->_Mycont != _IGNORE_MYCONT) { _SCL_SECURE_VALIDATE(this->_Mycont != NULL); _SCL_SECURE_VALIDATE_RANGE( _Myptr + _Off <= (((_Mystring *)this->_Mycont)->_Myptr() + ((_Mystring *)this->_Mycont)->_Mysize) && _Myptr + _Off >= ((_Mystring *)this->_Mycont)->_Myptr()); } _Myptr += _Off; return (*this); }
Which makes sense, as it's checking we don't assign past the end of our underlying string, which is exactly what line 395 of options_descriptions.cpp does in multiline conditions.
I'd still consider this check broken, since we never *access* via the invalid iterator, we immediately check if it's past the end and reset it back. Anyway, this is fixed now, both on trunk and release branch. - Volodya

Hello, I'm not sure if it is still topic but here is the minimum code to reproduce the problem. [----CODE----] #include <string> #include <algorithm> int main() { std::string par ( "produces help message slkfjsd lskdjf slkjf sdlkfj sdlkfj sdlkfj sdf lksdj" ); unsigned int line_length = 79, indent = 33; std::string::const_iterator line_begin = par.begin(); std::string::const_iterator line_end = line_begin + (line_length - indent); // find last ' ' in the second half of the current paragraph line std::string::const_iterator last_space = std::find(std::reverse_iterator<std::string::const_iterator>(line_end - 1), std::reverse_iterator<std::string::const_iterator>(line_begin - 1), ' ') .base(); return 0; } Regards, Elviin

elviin wrote:
std::string::const_iterator last_space =
std::find(std::reverse_iterator<std::string::const_iterator>(line_end
- 1), std::reverse_iterator<std::string::const_iterator>(line_begin - 1), ' ') .base();
I believe *that* bug is fixed quite some time ago. Thanks, Volodya
participants (3)
-
elviin
-
Trent Nelson
-
Vladimir Prus