From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 963953883F0E; Wed, 14 Dec 2022 14:11:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 963953883F0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671027092; bh=UCwF2jB3Z1Owh3NGWxrqHUmeRiCrMtmcRkvMxAwrCSo=; h=From:To:Subject:Date:From; b=g8H4+nwdPep2ROM6f4NwB1H+4Cmc0ZD6+ZYtxGIbZB0xhYQPU1NwsaeqTYy/BRQar UFWy3mJhl5HOxMCtQrB949VXWQAdDIHxFnslMNmSEcdHpfbFWvZGXICzDhAbc2PQdg u+G7fkqUbs9tdRMy+8srD8Jfb4KFSZUBOGIBh3X0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-4701] libstdc++: Fix size passed to operator delete [PR108097] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 049dccd080c6ad74a8d0923c57c8a488a9a18496 X-Git-Newrev: 881c6cabce5d0b27285ed41bd6dabdf48848cce7 Message-Id: <20221214141132.963953883F0E@sourceware.org> Date: Wed, 14 Dec 2022 14:11:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:881c6cabce5d0b27285ed41bd6dabdf48848cce7 commit r13-4701-g881c6cabce5d0b27285ed41bd6dabdf48848cce7 Author: Jonathan Wakely 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. 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 83c6463b0d8..402be3e828e 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -608,8 +608,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if constexpr (is_same_v>) { - __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(__p);