add null check

v1
Brett 2024-06-26 18:55:11 -04:00
parent 2a34be2e7b
commit cdb91d8007
3 changed files with 15 additions and 12 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake) include(cmake/color.cmake)
set(BLT_VERSION 0.17.19) set(BLT_VERSION 0.17.20)
set(BLT_TEST_VERSION 0.0.1) set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT) set(BLT_TARGET BLT)

View File

@ -468,20 +468,23 @@ namespace blt
size = std::max(size_, size); size = std::max(size_, size);
size = blt::mem::next_byte_allocation(size); size = blt::mem::next_byte_allocation(size);
T* new_buffer = new T[size]; T* new_buffer = new T[size];
if constexpr (std::is_trivially_copyable_v<T>) if (buffer_ != nullptr)
{ {
std::memcpy(new_buffer, buffer_, size_ * sizeof(T)); if constexpr (std::is_trivially_copyable_v<T>)
} else
{
if constexpr (std::is_copy_constructible_v<T> && !std::is_move_constructible_v<T>)
{ {
for (size_t i = 0; i < size_; i++) std::memcpy(new_buffer, buffer_, size_ * sizeof(T));
new_buffer[i] = T(buffer_[i]);
} else } else
for (size_t i = 0; i < size_; i++) {
new_buffer[i] = std::move(buffer_[i]); if constexpr (std::is_copy_constructible_v<T> && !std::is_move_constructible_v<T>)
{
for (size_t i = 0; i < size_; i++)
new_buffer[i] = T(buffer_[i]);
} else
for (size_t i = 0; i < size_; i++)
new_buffer[i] = std::move(buffer_[i]);
}
delete[] buffer_;
} }
delete[] buffer_;
buffer_ = new_buffer; buffer_ = new_buffer;
size_ = size; size_ = size;
} }

@ -1 +1 @@
Subproject commit d88c5e15079047777b418132ece5879e7c9aaa2b Subproject commit 10368163ab1f4367d2f0685b5928b1c973ebd1ec