Bug in options_description.cpp when offer a long program options to boost::program_options
If you provide a long program options description while using boost, you will encounter such issue, if you using debug version, you will see a debug assertion failed alert, if you using release version, your program will be crashed. following codes can be used to reproduce this issue #include <iostream> #include <boost/program_options.hpp> using namespace std; int main(int argc, char* argv[]) { namespace po = boost::program_options; po::options_description desc("supported options"); desc.add_options() ("help,h", "display this help message,this help will be printed out if you not provide option here!"); std::cout << desc << "\n"; } I have trace this issue, it is located in function format_paragraph in the file options_description.cpp, namespace { void format_paragraph(std::ostream& os, std::string par, unsigned first_column_width, unsigned line_length) { ...... // prevent chopped words // if (lastchar != ' ') && // ((exists(lastchar + 1) && (lastchar + 1 != ' ')) if ((*(line_end - 1) != ' ') && ((line_end < par_end) && (*line_end != ' '))) { // find last ' ' in the second half of the current paragraph line string::const_iterator last_space = find(reverse_iterator<string::const_iterator>(line_end - 1), reverse_iterator<string::const_iterator>(line_begin - 1), ' ') .base(); if (last_space != line_begin - 1) { ...... } if option description is long enough, the find function will be called, and "reverse_iterator<string::const_iterator>(line_begin - 1)" will lead to this issue, may "line_begin - 1" access a invalid space. If there have some guys to confirm it was a bug in boost?
Jack Shi wrote:
If you provide a long program options description while using boost, you will encounter such issue, if you using debug version, you will see a debug assertion failed alert, if you using release version, your program will be crashed. following codes can be used to reproduce this issue ....... if option description is long enough, the find function will be called, and "reverse_iterator<string::const_iterator>(line_begin - 1)" will lead to this issue, may "line_begin - 1" access a invalid space.
If there have some guys to confirm it was a bug in boost?
Please try CVS version. - Volodya
participants (2)
-
Jack Shi
-
Vladimir Prus