| 698 | |
| 699 | template <typename T, std::size_t SIZE, typename Allocator> |
| 700 | void basic_memory_buffer<T, SIZE, Allocator>::grow(std::size_t size) { |
| 701 | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
| 702 | if (size > 1000) throw std::runtime_error("fuzz mode - won't grow that much"); |
| 703 | #endif |
| 704 | std::size_t old_capacity = this->capacity(); |
| 705 | std::size_t new_capacity = old_capacity + old_capacity / 2; |
| 706 | if (size > new_capacity) new_capacity = size; |
| 707 | T* old_data = this->data(); |
| 708 | T* new_data = std::allocator_traits<Allocator>::allocate(*this, new_capacity); |
| 709 | // The following code doesn't throw, so the raw pointer above doesn't leak. |
| 710 | std::uninitialized_copy(old_data, old_data + this->size(), |
| 711 | internal::make_checked(new_data, new_capacity)); |
| 712 | this->set(new_data, new_capacity); |
| 713 | // deallocate must not throw according to the standard, but even if it does, |
| 714 | // the buffer already uses the new storage and will deallocate it in |
| 715 | // destructor. |
| 716 | if (old_data != store_) Allocator::deallocate(old_data, old_capacity); |
| 717 | } |
| 718 | |
| 719 | using memory_buffer = basic_memory_buffer<char>; |
| 720 | using wmemory_buffer = basic_memory_buffer<wchar_t>; |
nothing calls this directly
no test coverage detected