diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-11-14 14:25:52 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-11-18 08:22:27 +0000 |
commit | dffc37deaddf08bd11208a459496b30021700203 (patch) | |
tree | 35c46e6395c8bf8f8546040afbe1a304c521fdad /gcc | |
parent | 7b8b96a327f2201531c0a2b32db490532db4aa39 (diff) | |
download | gcc-dffc37deaddf08bd11208a459496b30021700203.zip gcc-dffc37deaddf08bd11208a459496b30021700203.tar.gz gcc-dffc37deaddf08bd11208a459496b30021700203.tar.bz2 |
libstdc++: Fix invalid casts in unordered container merge functions
François pointed out that static_cast<__node_ptr>(&_M_before_begin) is
invalid, because _M_before_begin is only a node-base not a node.
Refactor the new merge overloads to only cast when we know we have a
valid node.
He also pointed out some optimizations to allow reusing hash codes that
might be cached in the node. The _M_src_hash_code function already has
the right logic to decide when a cached hash code can be reused by a
different _Hashtable object.
libstdc++-v3/ChangeLog:
* include/bits/hashtable.h (_Hashtable::_M_src_hash_code):
Improve comments.
(_Hashtable::_M_merge_unique(_Hashtable&)): Use pointer_traits
to get before-begin pointer. Only use static_cast on valid
nodes, not the before-begin pointer. Reuse a hash code cached in
the node when possible.
(_Hashtable::_M_merge_multi(_Hashtable&)): Likewise.
Reviewed-by: François Dumont <fdumont@gcc.gnu.org>
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions