id summary reporter owner description type status milestone component version severity resolution keywords cc 4008 Segfault in program_options::parse_command_line when compiled with -fshort-enums Severin Kacianka Vladimir Prus "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 #include #include 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(),""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() << "".\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::allocator > >, std::vector >&>::clear() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EFBC: boost::function1, std::allocator > >, std::vector >&>::~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::~basic_command_line_parser() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x8056277: boost::program_options::basic_parsed_options boost::program_options::parse_command_line(int, char**, boost::program_options::options_description const&, int, boost::function1, 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::allocator > >, std::vector >&>::clear() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EFBC: boost::function1, std::allocator > >, std::vector >&>::~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::~basic_command_line_parser() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x8056277: boost::program_options::basic_parsed_options boost::program_options::parse_command_line(int, char**, boost::program_options::options_description const&, int, boost::function1, 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::allocator > >, std::vector >&>::clear(boost::detail::function::function_buffer&) (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EF99: boost::function1, std::allocator > >, std::vector >&>::clear() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EFBC: boost::function1, std::allocator > >, std::vector >&>::~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::~basic_command_line_parser() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x8056277: boost::program_options::basic_parsed_options boost::program_options::parse_command_line(int, char**, boost::program_options::options_description const&, int, boost::function1, 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::allocator > >, std::vector >&>::clear(boost::detail::function::function_buffer&) (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EF99: boost::function1, std::allocator > >, std::vector >&>::clear() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EFBC: boost::function1, std::allocator > >, std::vector >&>::~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::~basic_command_line_parser() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x8056277: boost::program_options::basic_parsed_options boost::program_options::parse_command_line(int, char**, boost::program_options::options_description const&, int, boost::function1, 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::allocator > >, std::vector >&>::clear() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EFBC: boost::function1, std::allocator > >, std::vector >&>::~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::~basic_command_line_parser() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x8056277: boost::program_options::basic_parsed_options boost::program_options::parse_command_line(int, char**, boost::program_options::options_description const&, int, boost::function1, 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::allocator > >, std::vector >&>::clear() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x804EFBC: boost::function1, std::allocator > >, std::vector >&>::~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::~basic_command_line_parser() (in /home/severin/swpr-02/examples/conf/a.out) ==11266== by 0x8056277: boost::program_options::basic_parsed_options boost::program_options::parse_command_line(int, char**, boost::program_options::options_description const&, int, boost::function1, 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 :-)" Bugs closed Boost 1.43.0 program_options Boost 1.42.0 Showstopper invalid