std::_Rb_tree_increment (__x=0x1) 的分段错误
迭代集合时出现分段错误。
堆栈跟踪指向:
0x000000081193ccc5 in std::_Rb_tree_increment (__x=0x1) at /libstdc++/src/tree.cc:68
0x0000000806c3107e in std::_Rb_tree_const_iterator<test *>::operator++ at stl_tree.h:266
但我没有得到更多信息,但崩溃的最后一行如下。
迭代器是在一个集合上。
typedef std::set<test*,test_less> test_set_t;
test_set_t& set(bt->getSet()); // getSet() will return reference to the class bt member variable set
test_set_t::iterator pos = set.begin();
test empty(val);
test* last_ptr = ∅
for (; pos != set.end(); last_ptr = *pos++) { // gdb shows this as last line
我看不到这个问题。提前致谢。
I get a segmentation fault when iterating over a set.
The stack trace points to:
0x000000081193ccc5 in std::_Rb_tree_increment (__x=0x1) at /libstdc++/src/tree.cc:68
0x0000000806c3107e in std::_Rb_tree_const_iterator<test *>::operator++ at stl_tree.h:266
but I get nothing more informative but the last line of crash is as below.
The iterator is over a set.
typedef std::set<test*,test_less> test_set_t;
test_set_t& set(bt->getSet()); // getSet() will return reference to the class bt member variable set
test_set_t::iterator pos = set.begin();
test empty(val);
test* last_ptr = ∅
for (; pos != set.end(); last_ptr = *pos++) { // gdb shows this as last line
I cannot see the issue. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很可能该集合为空,或者您在迭代时删除了
pos
所指向的项目。Most likely either the set is empty or you erased the item
pos
was pointing to while iterating.我遇到类似的问题
_Rb_tree_increment 可能会被锁定,如果传递给它的迭代器无效或损坏,例如空集的结束迭代器。
所以我们可以插入Sentinel节点来保证set不会为null或者检查set为null。
I meet the similar problem
_Rb_tree_increment may be locked if the iterator passed to it is invalid or corrupted, such as the end iterator of an empty set.
So we can insert Sentinel node to guarantee set will not null or check set is null.