libstdc++: [_Hashtable] Do not reuse untrusted cached hash code
On merge, reuse a merged node's possibly cached hash code only if we are on the same type of hash and this hash is stateless. Usage of function pointers or std::function as hash functor will prevent reusing cached hash code. libstdc++-v3/ChangeLog * include/bits/hashtable_policy.h (_Hash_code_base::_M_hash_code(const _Hash&, const _Hash_node_value<>&)): Remove. (_Hash_code_base::_M_hash_code<_H2>(const _H2&, const _Hash_node_value<>&)): Remove. * include/bits/hashtable.h (_M_src_hash_code<_H2>(const _H2&, const key_type&, const __node_value_type&)): New. (_M_merge_unique<>, _M_merge_multi<>): Use latter. * testsuite/23_containers/unordered_map/modifiers/merge.cc (test04, test05, test06): New test cases.
Showing
- libstdc++-v3/include/bits/hashtable.h 17 additions, 2 deletionslibstdc++-v3/include/bits/hashtable.h
- libstdc++-v3/include/bits/hashtable_policy.h 0 additions, 13 deletionslibstdc++-v3/include/bits/hashtable_policy.h
- libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/merge.cc 173 additions, 5 deletions.../testsuite/23_containers/unordered_map/modifiers/merge.cc
Loading
Please register or sign in to comment