From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id DDDB4382E19E; Wed, 14 Dec 2022 14:18:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDDB4382E19E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671027532; bh=QlLdxZcOv++wHFuF0Cz0teA5TRxYAQ8gtWXHJVZlQpo=; h=From:To:Subject:Date:From; b=RTxNclBCHS6I3haBf2+SG4i3DnCUAP+qDK+vRJN6lmYjxgYuXslfUKijuG3QF0xNE Wfp9QL5ZTvioeuD6tuZIWfwPeDC4ysxJttKWEA5e3tyyb0WkbpyOUeC2Y7NlKqQEKp +sjilaxdf7FP/1AxgYaEu4KDWczGuzFY8rRr2eDw= 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 r12-8985] libstdc++: Fix size passed to operator delete [PR108097] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 6340b1c2361979d120ba6fa3663a17a8cbb756a8 X-Git-Newrev: e9d58614b0b8eebd64d568fa22cd31faaa5f8dce Message-Id: <20221214141852.DDDB4382E19E@sourceware.org> Date: Wed, 14 Dec 2022 14:18:52 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e9d58614b0b8eebd64d568fa22cd31faaa5f8dce commit r12-8985-ge9d58614b0b8eebd64d568fa22cd31faaa5f8dce 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. (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>) { - __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);