]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix size passed to operator delete [PR108097]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 14 Dec 2022 11:58:05 +0000 (11:58 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 14 Dec 2022 14:13:39 +0000 (14:13 +0000)
The number of elements gets stored in _M_capacity so use a separate
variable for the number of bytes to allocate.

libstdc++-v3/ChangeLog:

PR libstdc++/108097
* include/std/stacktrace (basic_stracktrace::_Impl): Do not
multiply N by sizeof(value_type) when allocating.

(cherry picked from commit 881c6cabce5d0b27285ed41bd6dabdf48848cce7)

libstdc++-v3/include/std/stacktrace

index 8e6c79a2f4ff6523af3d54d688dfd00a884bad80..a067d629a16c4f3f396b7b298fbe8106a051c078 100644 (file)
@@ -600,8 +600,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            {
              if constexpr (is_same_v<allocator_type, allocator<value_type>>)
                {
-                 __n *= sizeof(value_type);
-                 void* const __p = _GLIBCXX_OPERATOR_NEW (__n, nothrow_t{});
+                 // For std::allocator we use nothrow-new directly so we
+                 // don't need to handle bad_alloc exceptions.
+                 size_t __nb = __n * sizeof(value_type);
+                 void* const __p = _GLIBCXX_OPERATOR_NEW (__nb, nothrow_t{});
                  if (__p == nullptr) [[unlikely]]
                    return nullptr;
                  _M_frames = static_cast<pointer>(__p);