diff --git a/stl/inc/deque b/stl/inc/deque index 2800f21144..176b311623 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1557,9 +1557,15 @@ private: _Newsize *= 2; } + size_type _Allocsize = _Newsize; + size_type _Myboff = _Myoff() / _Block_size; - _Mapptr _Newmap = _Allocate_at_least_helper(_Almap, _Newsize); + _Mapptr _Newmap = _Allocate_at_least_helper(_Almap, _Allocsize); _Mapptr _Myptr = _Newmap + _Myboff; + _STL_ASSERT(_Allocsize >= _Newsize, "_Allocsize >= _Newsize"); + while (_Newsize <= _Allocsize / 2) { + _Newsize *= 2; + } _Count = _Newsize - _Mapsize(); diff --git a/tests/std/tests/GH_003570_allocate_at_least/test.cpp b/tests/std/tests/GH_003570_allocate_at_least/test.cpp index 1814ff4e2b..37408cf478 100644 --- a/tests/std/tests/GH_003570_allocate_at_least/test.cpp +++ b/tests/std/tests/GH_003570_allocate_at_least/test.cpp @@ -51,7 +51,7 @@ struct signalling_allocator { allocation_result allocate_at_least(size_t count) { allocate_at_least_signal.set(); - return {allocate(count * 2), count * 2}; + return {allocate(count * 2 + 1), count * 2 + 1}; } void deallocate(T* ptr, size_t) noexcept { @@ -72,10 +72,15 @@ void test_container() { } void test_deque() { - deque> d; - d.resize(100); + deque> d; + for (size_t i = 0; i < 100; ++i) { + d.push_back(i); + } assert(allocate_at_least_signal.consume()); assert(d.size() == 100); + for (size_t i = 0; i < 100; ++i) { + assert(d[i] == i); + } } void test_stream_overflow(auto& stream) {