c++ - SEGV in gcc's std::unordered_map -
i have encountered segv in gcc 4.7.2's unordered_map
in find()
calls _m_find_node
, in turn calls _m_find_before_node
, passing in bucket number, key we're searching for, , hash code.
in _m_find_before_node
, looks first node in bucket in question:
_basenode* __prev_p = _m_buckets[__n];
and gets node following this:
_node* __p = static_cast<_node*>(__prev_p->_m_nxt);
the problem __prev_p->_m_nxt
null; , _m_equals
tries dereference , causes seg fault.
i'm not 100% clued on inner workings of unordered_map
- requirement first node in bucket's _m_nxt
non-null, or bug?
the code in question here:
// find node key compares equal k in bucket n. return nullptr // if no node found. template<typename _key, typename _value, typename _allocator, typename _extractkey, typename _equal, typename _h1, typename _h2, typename _hash, typename _rehashpolicy, bool __chc, bool __cit, bool __uk> typename _hashtable<_key, _value, _allocator, _extractkey, _equal, _h1, _h2, _hash, _rehashpolicy, __chc, __cit, __uk>::_basenode* _hashtable<_key, _value, _allocator, _extractkey, _equal, _h1, _h2, _hash, _rehashpolicy, __chc, __cit, __uk>:: _m_find_before_node(size_type __n, const key_type& __k, typename _hashtable::_hash_code_type __code) const { _basenode* __prev_p = _m_buckets[__n]; if (!__prev_p) return nullptr; _node* __p = static_cast<_node*>(__prev_p->_m_nxt); // __p null here!! (;; __p = __p->_m_next()) { if (this->_m_equals(__k, __code, __p)) return __prev_p; if (!(__p->_m_nxt) || _m_bucket_index(__p->_m_next()) != __n) break; __prev_p = __p; } return nullptr; }
i'm not 100% clued on inner workings of
unordered_map
- requirement first node in bucket's_m_nxt
non-null, or bug?
the question specific gcc's implementation, i'm pretty sure if _m_buckets[__n]
non-null _m_buckets[__n]->_m_nxt
should non-null too.
i.e. if bucket empty _m_buckets[__n]==nullptr
, if bucket non-empty _m_buckets[__n]->_m_nxt
first node in bucket.
try building -d_glibcxx_debug
, see if identifies problem code, it's possible there's bug it's more you've corrupted container somehow or using wrong.
Comments
Post a Comment