aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-06-10 13:51:52 +0100
committerJonathan Wakely <jwakely@redhat.com>2024-06-12 15:06:47 +0100
commit3f2f9059c7f76ff888e9d0e8f10dec6f48e346c9 (patch)
tree09519b032f716562d1edff0663ddef866c918539
parentadcc815a01ae009d2768b6afb546e357bd37bbd2 (diff)
downloadgcc-3f2f9059c7f76ff888e9d0e8f10dec6f48e346c9.zip
gcc-3f2f9059c7f76ff888e9d0e8f10dec6f48e346c9.tar.gz
gcc-3f2f9059c7f76ff888e9d0e8f10dec6f48e346c9.tar.bz2
libstdc++: Do not use memset in _Hashtable::clear()
Using memset is incorrect if the __bucket_ptr type is non-trivial, or does not use an all-zero bit pattern for its null value. Replace the three uses of memset with std::fill_n to set the pointers to nullptr. libstdc++-v3/ChangeLog: * include/bits/hashtable.h (_Hashtable::clear): Do not use memset to zero out bucket pointers. (_Hashtable::_M_assign_elements): Likewise.
-rw-r--r--libstdc++-v3/include/bits/hashtable.h10
1 files changed, 4 insertions, 6 deletions
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index 6e78cb7..983aa90 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -34,6 +34,7 @@
#include <bits/hashtable_policy.h>
#include <bits/enable_special_members.h>
+#include <bits/stl_algobase.h> // fill_n
#include <bits/stl_function.h> // __has_is_transparent_t
#if __cplusplus > 201402L
# include <bits/node_handle.h>
@@ -1376,8 +1377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_bucket_count = __ht._M_bucket_count;
}
else
- __builtin_memset(_M_buckets, 0,
- _M_bucket_count * sizeof(__node_base_ptr));
+ std::fill_n(_M_buckets, _M_bucket_count, nullptr);
__try
{
@@ -1400,8 +1400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_buckets = __former_buckets;
_M_bucket_count = __former_bucket_count;
}
- __builtin_memset(_M_buckets, 0,
- _M_bucket_count * sizeof(__node_base_ptr));
+ std::fill_n(_M_buckets, _M_bucket_count, nullptr);
__throw_exception_again;
}
}
@@ -2582,8 +2581,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
clear() noexcept
{
this->_M_deallocate_nodes(_M_begin());
- __builtin_memset(_M_buckets, 0,
- _M_bucket_count * sizeof(__node_base_ptr));
+ std::fill_n(_M_buckets, _M_bucket_count, nullptr);
_M_element_count = 0;
_M_before_begin._M_nxt = nullptr;
}