public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53490] New: Segmentation Fault when accessing std::set
@ 2012-05-25 18:13 ja11sop at yahoo dot co.uk
  2012-05-25 18:22 ` [Bug c++/53490] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ja11sop at yahoo dot co.uk @ 2012-05-25 18:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53490

             Bug #: 53490
           Summary: Segmentation Fault when accessing std::set
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ja11sop@yahoo.co.uk


The following g++ 4.7 compiled code, when executed on x86_64 Debian Sid,
segfaults.

The code is a reduced sample from a much larger code-base of production code
that ran ok with gcc4.6. With more time I could reduce it further but this
already consistently hits the problem and produces a useful back trace.

I have this as a blocker because all our application code essentially executes
something similar to this and so now all our applications segfault when built
with gcc4.7. Also I cannot come up with a trivial work-around without
re-writing large parts of the code base.

CODE:
//------------------------------------------------------------------

// Boost Library Includes
#include <boost/program_options.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/property_tree/ptree.hpp>

// C++ Standard Library Includes
#include <string>
#include <set>


typedef boost::property_tree::ptree                     property_tree_t;
typedef boost::shared_ptr<property_tree_t>              shared_property_tree_t;

void store_properties( int argc, const char* argv[] )
{
    typedef boost::program_options::options_description options_description_t;
    typedef boost::program_options::variables_map       variables_t;

    options_description_t Options( "Base Options" );
    Options.add_options()( "help,h", "Display Help" );

    variables_t Variables( new variables_t() );

    boost::program_options::parsed_options ParsedOptions = parse_command_line(
argc, argv, Options );
    boost::program_options::store( ParsedOptions, Variables );
    boost::program_options::notify( Variables );
}


typedef std::string                     string_t;
typedef std::set<string_t>              string_set_t;
typedef boost::shared_ptr<string_set_t> shared_string_set_t;

shared_string_set_t get_unique_keys( const string_t& Key, const
property_tree_t& PropertyTree )
{
    if( auto Children = PropertyTree.get_child_optional( Key ) )
    {
        shared_string_set_t Values( new string_set_t() );

        for( auto& Child : *Children )
        {
            // This line is required for the segfault
            Values->insert( Child.first );
        }
        return Values;
    }
    return shared_string_set_t();
}


int main( int argc, char* argv[] )
{
    const char* DummyArgv[] = { "std_set_bug_test", "--help", 0 };

    shared_property_tree_t PropertyTree =
boost::make_shared<property_tree_t>();

    store_properties( 2, DummyArgv );

    // No need to call this code
    //auto UniqueKeys = get_unique_keys( "log.sink", *PropertyTree );

    return 0;
}

//------------------------------------------------------------------

Code compiled with:

-Wall -g -std=c++11

Linked *statically* with the boost 1.49 program_options library.

BACKTRACE:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7933427 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) bt
#0  0x00007ffff7933427 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x000000000046412d in std::_Rb_tree_iterator<std::string>::operator--
(this=0x7fffffffdc60)
    at /usr/include/c++/4.7/bits/stl_tree.h:203
#2  0x0000000000462caa in std::pair<std::_Rb_tree_iterator<std::string>, bool>
std::_Rb_tree<std::string, std::string, std::_Identity<std::string>,
std::less<std::string>, std::allocator<std::string>
>::_M_insert_unique<std::string const&>(std::string const&) ()
#3  0x0000000000461b25 in std::set<std::string, std::less<std::string>,
std::allocator<std::string> >::insert(std::string const&) ()
#4  0x000000000047aeb1 in boost::program_options::store (options=..., xm=...,
utf8=false)
    at libs/program_options/src/variables_map.cpp:98
#5  0x0000000000460350 in store_properties(int, char const**) ()
#6  0x00000000004606ab in main ()
(gdb)


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-05-28  9:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
2012-05-25 18:22 ` [Bug c++/53490] " redi at gcc dot gnu.org
2012-05-25 18:24 ` redi at gcc dot gnu.org
2012-05-25 20:42 ` daniel.kruegler at googlemail dot com
2012-05-25 22:16 ` ja11sop at yahoo dot co.uk
2012-05-25 22:51 ` ja11sop at yahoo dot co.uk
2012-05-26  0:14 ` redi at gcc dot gnu.org
2012-05-26 13:26 ` ja11sop at yahoo dot co.uk
2012-05-28  9:32 ` ja11sop at yahoo dot co.uk
2012-05-28  9:40 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).