[Boost-bugs] [Boost C++ Libraries] #4008: Segfault in program_options::parse_command_line when compiled with -fshort-enums

Subject: [Boost-bugs] [Boost C++ Libraries] #4008: Segfault in program_options::parse_command_line when compiled with -fshort-enums
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-03-14 16:23:56


#4008: Segfault in program_options::parse_command_line when compiled with -fshort-
enums
----------------------------------------------------------+-----------------
 Reporter: Severin Kacianka <severin@…> | Owner: vladimir_prus
     Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: program_options
  Version: Boost 1.42.0 | Severity: Showstopper
 Keywords: |
----------------------------------------------------------+-----------------
 Hello,

 I am new to C++ and bug finding in general, so I hope am not reporting
 something obvious.
 When diving into program_options I wrote the following sample program:

 {{{
 // test.cpp
 #include <boost/program_options.hpp>
 #include <iostream>
 #include <fstream>

 namespace po = boost::program_options;

 int main(int argc, char **argv)
 {

     int result = EXIT_SUCCESS;
         po::options_description desc("Allowed options");
         desc.add_options()
                 ("help", "Displays help message")
                 ("port",po::value<int>(),"Port to use")
         ;
         po::options_description cmdline_options;
         cmdline_options.add(desc);
         po::options_description config_file_options;
         config_file_options.add(desc);
         po::variables_map vm;
         po::store(po::parse_command_line(argc, argv, desc), vm);
         po::notify(vm);

         if (vm.count("port")) {
                 std::cout << "port was set to "
                  << vm["port"].as<int>() << ".\n";
         } else {
                 std::cout << "port was not set.\n";
         }

         return result;
 }
 }}}

 When compiled 'normally' it works:
 {{{
 $ g++ test.cpp -lboost_program_options
 $ ./a.out --port 60
 port was set to 60.
 }}}
 but when I compile it with -fshort-enums it segfaults:
 {{{
 $ g++ -fshort-enums test.cpp -lboost_program_options
 $./a.out
 Segmentation fault
 }}}

 My gcc version:
 {{{
  g++ -v
 Reading specs from /usr/lib/gcc/i486-slackware-linux/4.2.4/specs
 Target: i486-slackware-linux
 Configured with: ../gcc-4.2.4/configure --prefix=/usr --enable-shared
 --enable-languages=ada,c,c++,fortran,java,objc --enable-threads=posix
 --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --with-
 arch=i486 --target=i486-slackware-linux --host=i486-slackware-linux
 Thread model: posix
 gcc version 4.2.4
 }}}

 Valgrind output of the crashing binary:
 {{{
 valgrind a.out
 ==11266== Memcheck, a memory error detector.
 ==11266== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
 ==11266== Using LibVEX rev 1804, a library for dynamic binary translation.
 ==11266== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
 ==11266== Using valgrind-3.3.0, a dynamic binary instrumentation
 framework.
 ==11266== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
 ==11266== For more details, rerun with: -v
 ==11266==
 ==11266== Conditional jump or move depends on uninitialised value(s)
 ==11266== at 0x804EF64:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::clear() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EFBC:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::~function1() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050AD7:
 boost::program_options::detail::cmdline::~cmdline() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050B6B:
 boost::program_options::basic_command_line_parser<char>::~basic_command_line_parser()
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8056277:
 boost::program_options::basic_parsed_options<char>
 boost::program_options::parse_command_line<char>(int, char**,
 boost::program_options::options_description const&, int,
 boost::function1<std::pair<std::string, std::string>, std::string const&>)
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804DE66: main (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266==
 ==11266== Conditional jump or move depends on uninitialised value(s)
 ==11266== at 0x804EF7A:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::clear() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EFBC:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::~function1() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050AD7:
 boost::program_options::detail::cmdline::~cmdline() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050B6B:
 boost::program_options::basic_command_line_parser<char>::~basic_command_line_parser()
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8056277:
 boost::program_options::basic_parsed_options<char>
 boost::program_options::parse_command_line<char>(int, char**,
 boost::program_options::options_description const&, int,
 boost::function1<std::pair<std::string, std::string>, std::string const&>)
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804DE66: main (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266==
 ==11266== Use of uninitialised value of size 4
 ==11266== at 0x804EF39:
 boost::detail::function::basic_vtable1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string>
>&>::clear(boost::detail::function::function_buffer&) (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EF99:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::clear() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EFBC:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::~function1() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050AD7:
 boost::program_options::detail::cmdline::~cmdline() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050B6B:
 boost::program_options::basic_command_line_parser<char>::~basic_command_line_parser()
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8056277:
 boost::program_options::basic_parsed_options<char>
 boost::program_options::parse_command_line<char>(int, char**,
 boost::program_options::options_description const&, int,
 boost::function1<std::pair<std::string, std::string>, std::string const&>)
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804DE66: main (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266==
 ==11266== Use of uninitialised value of size 4
 ==11266== at 0x804EF42:
 boost::detail::function::basic_vtable1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string>
>&>::clear(boost::detail::function::function_buffer&) (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EF99:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::clear() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EFBC:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::~function1() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050AD7:
 boost::program_options::detail::cmdline::~cmdline() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050B6B:
 boost::program_options::basic_command_line_parser<char>::~basic_command_line_parser()
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8056277:
 boost::program_options::basic_parsed_options<char>
 boost::program_options::parse_command_line<char>(int, char**,
 boost::program_options::options_description const&, int,
 boost::function1<std::pair<std::string, std::string>, std::string const&>)
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804DE66: main (in
 /home/severin/swpr-02/examples/conf/a.out)
 vex x86->IR: unhandled instruction bytes: 0x67 0x5 0x8 0x0
 ==11266==
 ==11266== Invalid read of size 4
 ==11266== at 0x805A539: ???
 ==11266== by 0x804EF99:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::clear() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EFBC:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::~function1() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050AD7:
 boost::program_options::detail::cmdline::~cmdline() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050B6B:
 boost::program_options::basic_command_line_parser<char>::~basic_command_line_parser()
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8056277:
 boost::program_options::basic_parsed_options<char>
 boost::program_options::parse_command_line<char>(int, char**,
 boost::program_options::options_description const&, int,
 boost::function1<std::pair<std::string, std::string>, std::string const&>)
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804DE66: main (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== Address 0x0 is not stack'd, malloc'd or (recently) free'd
 ==11266==
 ==11266== Process terminating with default action of signal 11 (SIGSEGV)
 ==11266== Access not within mapped region at address 0x0
 ==11266== at 0x805A539: ???
 ==11266== by 0x804EF99:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::clear() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804EFBC:
 boost::function1<std::vector<boost::program_options::basic_option<char>,
 std::allocator<boost::program_options::basic_option<char> > >,
 std::vector<std::string, std::allocator<std::string> >&>::~function1() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050AD7:
 boost::program_options::detail::cmdline::~cmdline() (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8050B6B:
 boost::program_options::basic_command_line_parser<char>::~basic_command_line_parser()
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x8056277:
 boost::program_options::basic_parsed_options<char>
 boost::program_options::parse_command_line<char>(int, char**,
 boost::program_options::options_description const&, int,
 boost::function1<std::pair<std::string, std::string>, std::string const&>)
 (in /home/severin/swpr-02/examples/conf/a.out)
 ==11266== by 0x804DE66: main (in
 /home/severin/swpr-02/examples/conf/a.out)
 ==11266==
 ==11266== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 23 from 1)
 ==11266== malloc/free: in use at exit: 568 bytes in 33 blocks.
 ==11266== malloc/free: 39 allocs, 6 frees, 704 bytes allocated.
 ==11266== For counts of detected errors, rerun with: -v
 ==11266== searching for pointers to 33 not-freed blocks.
 ==11266== checked 119,684 bytes.
 ==11266==
 ==11266== LEAK SUMMARY:
 ==11266== definitely lost: 0 bytes in 0 blocks.
 ==11266== possibly lost: 136 bytes in 6 blocks.
 ==11266== still reachable: 432 bytes in 27 blocks.
 ==11266== suppressed: 0 bytes in 0 blocks.
 ==11266== Rerun with --leak-check=full to see details of leaked memory.
 Segmentation fault

 }}}

 If I can help you finding the cause, just write me an e-mail :-)

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4008>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC