Fix overflows in std::pmr::unsynchonized_pool_resource
authorJonathan Wakely <jwakely@redhat.com>
Tue, 13 Nov 2018 22:57:44 +0000 (22:57 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 13 Nov 2018 22:57:44 +0000 (22:57 +0000)
commit6bdd58f73a33cceba4da5966c17c356ecc22b0c6
tree0e71c13741900a8eab433e8a507bbfe08fc89621
parent874e50cbd5b254f1f171bf04ecdfeedc405dff5b
Fix overflows in std::pmr::unsynchonized_pool_resource

* src/c++17/memory_resource.cc (bitset::full()): Handle edge case
for _M_next_word maximum value.
(bitset::get_first_unset(), bitset::set(size_type)): Use
update_next_word() to update _M_next_word.
(bitset::update_next_word()): New function, avoiding wraparound of
unsigned _M_next_word member.
(bitset::max_word_index()): New function.
(chunk::chunk(void*, uint32_t, void*, size_t)): Add assertion.
(chunk::max_bytes_per_chunk()): New function.
(pool::replenish(memory_resource*, const pool_options&)): Prevent
_M_blocks_per_chunk from exceeding max_blocks_per_chunk or from
causing chunk::max_bytes_per_chunk() to be exceeded.
* testsuite/20_util/unsynchronized_pool_resource/allocate-max-chunks.cc:
New test.

From-SVN: r266087
libstdc++-v3/ChangeLog
libstdc++-v3/src/c++17/memory_resource.cc
libstdc++-v3/testsuite/20_util/unsynchronized_pool_resource/allocate-max-chunks.cc [new file with mode: 0644]