-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ | |
#include <cstring> // std::memcpy | ||
#include <initializer_list> // std::initializer_list | ||
#include <limits> // std::numeric_limits | ||
#include <memory> // std::allocator_traits | ||
#include <stdexcept> // std::runtime_error | ||
#include <string> // std::string | ||
#include <system_error> // std::system_error | ||
|
@@ -907,17 +906,16 @@ class basic_memory_buffer : public detail::buffer<T> { | |
static FMT_CONSTEXPR20 void grow(detail::buffer<T>& buf, size_t size) { | ||
detail::abort_fuzzing_if(size > 5000); | ||
auto& self = static_cast<basic_memory_buffer&>(buf); | ||
const size_t max_size = | ||
std::allocator_traits<Allocator>::max_size(self.alloc_); | ||
constexpr size_t max_size = | ||
detail::max_value<typename Allocator::size_type>() / sizeof(T); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
phprus
Contributor
|
||
size_t old_capacity = buf.capacity(); | ||
size_t new_capacity = old_capacity + old_capacity / 2; | ||
if (size > new_capacity) | ||
new_capacity = size; | ||
else if (new_capacity > max_size) | ||
new_capacity = size > max_size ? size : max_size; | ||
T* old_data = buf.data(); | ||
T* new_data = | ||
std::allocator_traits<Allocator>::allocate(self.alloc_, new_capacity); | ||
T* new_data = self.alloc_.allocate(new_capacity); | ||
// Suppress a bogus -Wstringop-overflow in gcc 13.1 (#3481). | ||
detail::assume(buf.size() <= new_capacity); | ||
// The following code doesn't throw, so the raw pointer above doesn't leak. | ||
|
This is non equal changes.
An Allocator can support allocate only less memory than the maximum size of the type.
The use of
std::allocator_traits
has been added for the case whenAllocator::max_size
is less thanmax_value<typename Allocator::size_type>
.We can use SFINAE to detect
Allocator::max_size()
or usemax_value
. See: https://en.cppreference.com/w/cpp/memory/allocator_traits/max_size