public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-8985] libstdc++: Fix size passed to operator delete [PR108097]
Date: Wed, 14 Dec 2022 14:18:52 +0000 (GMT)	[thread overview]
Message-ID: <20221214141852.DDDB4382E19E@sourceware.org> (raw)

https://gcc.gnu.org/g:e9d58614b0b8eebd64d568fa22cd31faaa5f8dce

commit r12-8985-ge9d58614b0b8eebd64d568fa22cd31faaa5f8dce
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Dec 14 11:58:05 2022 +0000

    libstdc++: Fix size passed to operator delete [PR108097]
    
    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)

Diff:
---
 libstdc++-v3/include/std/stacktrace | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace
index 8e6c79a2f4f..a067d629a16 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -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);

                 reply	other threads:[~2022-12-14 14:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221214141852.DDDB4382E19E@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).