Boost logo

Boost Users :

From: Jack Shi (lovin73_at_[hidden])
Date: 2007-02-24 14:06:29


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?



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