public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
@ 2020-03-12 22:39 redi at gcc dot gnu.org
2020-03-12 22:39 ` [Bug libstdc++/94160] " redi at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-12 22:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
Bug ID: 94160
Summary: std::pmr::pool_options::max_blocks_per_chunk=1 causes
pool resources to return null pointers
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: libstdc++
Assignee: redi at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
This calculation in __pool_resource::_M_alloc_pools() can result in
blocks_per_chunk being set to zero, and then _Pool::allocate always returns
null:
blocks_per_chunk
= std::min(blocks_per_chunk, _M_opts.max_blocks_per_chunk);
// Allow space for bitset to track which blocks are used/unused:
blocks_per_chunk *= 1 - 1.0 / (__CHAR_BIT__ * block_size);
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/94160] std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
@ 2020-03-12 22:39 ` redi at gcc dot gnu.org
2020-09-10 13:23 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-12 22:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-03-12
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/94160] std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
2020-03-12 22:39 ` [Bug libstdc++/94160] " redi at gcc dot gnu.org
@ 2020-09-10 13:23 ` redi at gcc dot gnu.org
2020-09-10 14:42 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-10 13:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Testcase:
#include <memory_resource>
int main()
{
std::pmr::unsynchronized_pool_resource upr({ 1, 32 });
auto* p = (int*)upr.allocate(4);
*p = 0;
return *p;
}
The returned pointer is null, leading to a segfault.
If libstdc++ is built with assertions enabled, the allocation aborts with:
../../../../../libstdc++-v3/src/c++17/memory_resource.cc:294:
std::pmr::{anonymous}::bitset::bitset(void*,
std::pmr::{anonymous}::bitset::size_type): Assertion 'empty()' failed.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/94160] std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
2020-03-12 22:39 ` [Bug libstdc++/94160] " redi at gcc dot gnu.org
2020-09-10 13:23 ` redi at gcc dot gnu.org
@ 2020-09-10 14:42 ` cvs-commit at gcc dot gnu.org
2020-09-10 14:45 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-10 14:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:30b41cfbb2dade63e52465234a725d1d02fe70aa
commit r11-3102-g30b41cfbb2dade63e52465234a725d1d02fe70aa
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Sep 10 15:39:15 2020 +0100
libstdc++: handle small max_blocks_per_chunk in pool resources [PR 94160]
When a pool resource is constructed with max_blocks_per_chunk=1 it ends
up creating a pool with blocks_per_chunk=0 which means it never
allocates anything. Instead it returns null pointers, which should be
impossible.
To avoid this problem, round the max_blocks_per_chunk value to a
multiple of four, so it's never smaller than four.
libstdc++-v3/ChangeLog:
PR libstdc++/94160
* src/c++17/memory_resource.cc (munge_options): Round
max_blocks_per_chunk to a multiple of four.
(__pool_resource::_M_alloc_pools()): Simplify slightly.
* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
Check that valid pointers are returned when small values are
used for max_blocks_per_chunk.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/94160] std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
` (2 preceding siblings ...)
2020-09-10 14:42 ` cvs-commit at gcc dot gnu.org
@ 2020-09-10 14:45 ` redi at gcc dot gnu.org
2020-09-21 20:18 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-10 14:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk so far, but I plan to backport it.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/94160] std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
` (3 preceding siblings ...)
2020-09-10 14:45 ` redi at gcc dot gnu.org
@ 2020-09-21 20:18 ` cvs-commit at gcc dot gnu.org
2020-09-21 23:13 ` cvs-commit at gcc dot gnu.org
2020-09-21 23:15 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-21 20:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:9ae110d4f8edd61cf56ee5fea62cadc8e781e8dc
commit r10-8780-g9ae110d4f8edd61cf56ee5fea62cadc8e781e8dc
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Sep 10 15:39:15 2020 +0100
libstdc++: handle small max_blocks_per_chunk in pool resources [PR 94160]
When a pool resource is constructed with max_blocks_per_chunk=1 it ends
up creating a pool with blocks_per_chunk=0 which means it never
allocates anything. Instead it returns null pointers, which should be
impossible.
To avoid this problem, round the max_blocks_per_chunk value to a
multiple of four, so it's never smaller than four.
libstdc++-v3/ChangeLog:
PR libstdc++/94160
* src/c++17/memory_resource.cc (munge_options): Round
max_blocks_per_chunk to a multiple of four.
(__pool_resource::_M_alloc_pools()): Simplify slightly.
* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
Check that valid pointers are returned when small values are
used for max_blocks_per_chunk.
(cherry picked from commit 30b41cfbb2dade63e52465234a725d1d02fe70aa)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/94160] std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
` (4 preceding siblings ...)
2020-09-21 20:18 ` cvs-commit at gcc dot gnu.org
@ 2020-09-21 23:13 ` cvs-commit at gcc dot gnu.org
2020-09-21 23:15 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-21 23:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:bdaf0ce0af30dfedac61ea1a7e842a45e55deb25
commit r9-8924-gbdaf0ce0af30dfedac61ea1a7e842a45e55deb25
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Sep 10 15:39:15 2020 +0100
libstdc++: handle small max_blocks_per_chunk in pool resources [PR 94160]
When a pool resource is constructed with max_blocks_per_chunk=1 it ends
up creating a pool with blocks_per_chunk=0 which means it never
allocates anything. Instead it returns null pointers, which should be
impossible.
To avoid this problem, round the max_blocks_per_chunk value to a
multiple of four, so it's never smaller than four.
libstdc++-v3/ChangeLog:
PR libstdc++/94160
* src/c++17/memory_resource.cc (munge_options): Round
max_blocks_per_chunk to a multiple of four.
(__pool_resource::_M_alloc_pools()): Simplify slightly.
* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
Check that valid pointers are returned when small values are
used for max_blocks_per_chunk.
(cherry picked from commit 30b41cfbb2dade63e52465234a725d1d02fe70aa)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/94160] std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
` (5 preceding siblings ...)
2020-09-21 23:13 ` cvs-commit at gcc dot gnu.org
@ 2020-09-21 23:15 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-21 23:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94160
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Target Milestone|--- |9.4
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 9.4 and 10.3
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-09-21 23:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 22:39 [Bug libstdc++/94160] New: std::pmr::pool_options::max_blocks_per_chunk=1 causes pool resources to return null pointers redi at gcc dot gnu.org
2020-03-12 22:39 ` [Bug libstdc++/94160] " redi at gcc dot gnu.org
2020-09-10 13:23 ` redi at gcc dot gnu.org
2020-09-10 14:42 ` cvs-commit at gcc dot gnu.org
2020-09-10 14:45 ` redi at gcc dot gnu.org
2020-09-21 20:18 ` cvs-commit at gcc dot gnu.org
2020-09-21 23:13 ` cvs-commit at gcc dot gnu.org
2020-09-21 23:15 ` redi at gcc dot gnu.org
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).