Fixes #151 ("Buffer overflow in monotonic_buffer_resource::do_allocate").

This commit is contained in:
Ion Gaztañaga
2020-07-12 11:07:50 +02:00
parent 4f37a023b0
commit 90de9533ec
2 changed files with 4 additions and 0 deletions

View File

@@ -1329,6 +1329,7 @@ use [*Boost.Container]? There are several reasons for that:
* [@https://github.com/boostorg/container/issues/145 GitHub #145: ['"Allocations not handled correctly in some cases of vector move with unequal allocators"]].
* [@https://github.com/boostorg/container/pull/146 GitHub #146: ['"Changes for Embarcadero C++ clang-based compilers, targeting Boost 1.74. Addition needed for Embarcardero clang-based compilers"]].
* [@https://github.com/boostorg/container/pull/148 GitHub #148: ['"Fix static initialization issues in pmr global resources"]].
* [@https://github.com/boostorg/container/issues/151 GitHub #151: ['"Buffer overflow in monotonic_buffer_resource::do_allocate"]].
[endsect]

View File

@@ -141,6 +141,9 @@ void* monotonic_buffer_resource::do_allocate(std::size_t bytes, std::size_t alig
//See if there is room in current buffer
std::size_t aligner = 0u;
if(this->remaining_storage(alignment, aligner) < bytes){
//The new buffer will be aligned to the strictest alignment so reset
//the aligner, which was needed for the old buffer.
aligner = 0u;
//Update next_buffer_size to at least bytes
this->increase_next_buffer_at_least_to(bytes);
//Now allocate and update internal data