From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2066) id E86AB383F850; Tue, 12 May 2020 07:22:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E86AB383F850 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589268159; bh=P01AfWZ+AK32agv9uBEz03k6cGwqQQ9qs1PR8jHXKdY=; h=From:To:Subject:Date:From; b=AfZrDW1ogQgYcjCsob1/UZpkNJobqU3GiFDr+m6mmVT6ZpbbiRK2Z3f6HyxGFyM2A rcpg6vQ/cKpCSLbSE/9fPUKg90CFCHR9VV9DOOkpBqnv4sskQeTwor9AAyUGiydmdt pJib7YU1w0IlhXZnU079n7Sp8mhZvrEAQbsVgam8= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jiu Fu Guo To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/guojiufu/heads/personal-branch)] libstdc++: Fix incorrect size calculation in PMR resource (PR 94906) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/users/guojiufu/heads/personal-branch X-Git-Oldrev: cc7e4de998cd2a31eb7c834fd427e7f16a99d60a X-Git-Newrev: bb27781b64162e1769df15e0c97e8d2145d2d10d Message-Id: <20200512072239.E86AB383F850@sourceware.org> Date: Tue, 12 May 2020 07:22:39 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 May 2020 07:22:40 -0000 https://gcc.gnu.org/g:bb27781b64162e1769df15e0c97e8d2145d2d10d commit bb27781b64162e1769df15e0c97e8d2145d2d10d Author: Jonathan Wakely Date: Mon May 4 21:13:28 2020 +0100 libstdc++: Fix incorrect size calculation in PMR resource (PR 94906) Calculating the size of a chunk being returned to the upstream allocator was done with a 32-bit type, so it wrapped if the chunk was 4GB or larger. I don't know how to test this without allocating 4GB, so there's no test in the testsuite. It has been tested manually with allocations sizes and alignments exceeding 4GB. PR libstdc++/94906 * src/c++17/memory_resource.cc (monotonic_buffer_resource::_Chunk::release): Use size_t for shift operands. Diff: --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/src/c++17/memory_resource.cc | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 739ab9eeb29..9cc811c884f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2020-05-04 Jonathan Wakely + + PR libstdc++/94906 + * src/c++17/memory_resource.cc + (monotonic_buffer_resource::_Chunk::release): Use size_t for shift + operands. + 2020-05-04 Nathan Sidwell PR libstdc++/94747 diff --git a/libstdc++-v3/src/c++17/memory_resource.cc b/libstdc++-v3/src/c++17/memory_resource.cc index 1acab19e306..95352b23537 100644 --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -228,8 +228,8 @@ namespace pmr if (__ch->_M_canary != (__ch->_M_size | __ch->_M_align)) return; // buffer overflow detected! - size_t __size = (1u << __ch->_M_size); - size_t __align = (1u << __ch->_M_align); + size_t __size = (size_t)1 << __ch->_M_size; + size_t __align = (size_t)1 << __ch->_M_align; void* __start = (char*)(__ch + 1) - __size; __r->deallocate(__start, __size, __align); }