在set :: insert上的Segfault

LoS*_*ano -1 c++ stl segmentation-fault

我在以下行之后遇到了段错误:

this->my_set.insert(my_string);
Run Code Online (Sandbox Code Playgroud)

该集已初始化,它包含std :: string.插入字符串不是指一个dandling指针,它是以null结尾的.集合中包含的所有其他字符串都不为null,并以'\ 0'结尾.

这是回溯:

#0  0xb7076bdb in std::_Rb_tree_insert_and_rebalance () from /usr/lib/libstdc++.so.6
#1  0xb7480795 in std::_Rb_tree<std::string, std::string, std::_Identity<std::string>, std::less<std::string>, std::allocator<std::string> >::_M_insert_ (
    this=0x97bf918, __x=0x0, __p=0x980aa78, __v=@0xaabfc1c4) at /usr/include/c++/4.3/bits/stl_tree.h:854<br/>
#2  0xb7480b96 in std::_Rb_tree<std::string, std::string, std::_Identity<std::string>, std::less<std::string>, std::allocator<std::string> >::_M_insert_unique (this=0x97bf918, __v=@0xaabfc1c4) at /usr/include/c++/4.3/bits/stl_tree.h:1148
#3  0xb74fab2d in std::set<std::string, std::less<std::string>, std::allocator<std::string> >::insert (this=0x97bf918, __x=@0xaabfc1c4)
    at /usr/include/c++/4.3/bits/stl_set.h:381
Run Code Online (Sandbox Code Playgroud)

任何的想法?


编辑

更多代码:

set<string> dangerous_messages; //placed in header file

            qpid::client::Message msg;
            msg = (*mylocal_queues)[queue]->get(10*1e9);
            string msgUID = msg.getHeaders().getAsString("UID");
            if(this->dangerous_messages.count(msgUID))
            {
                       warning("(read_local_queue) Duplicate message \""+msgUID+"\" discarded");
           }
           else
           {
                        msg.getHeaders().setString("BID", bid);
                        this->dangerous_messages.insert(msgUID);
            }
Run Code Online (Sandbox Code Playgroud)

使用gdb打印,我没有注意到集合或字符串中的任何损坏.

b.b*_*old 5

问题也可能位于其他地方.程序中某些其他位置的溢出可能会在您插入集合时导致段错误.插入只是识别错误的时间点,但根本不一定与错误有关.

考虑这个组成的例子:

vector<MyObj*> ptrs;
if/for/while (...)
{
    MyObj o;
    ptrs.push_back(&o);
}  // end of scopre for o
// Your heap is corrupted, but no segfault has to occur right away
...
// Your insertion occurs somewhere later
// No the program segfaults because of the problem you created earlier
Run Code Online (Sandbox Code Playgroud)