From cdb91d800781d2c2a8ad3b9a829ca6d52abaa6ea Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 26 Jun 2024 18:55:11 -0400 Subject: [PATCH] add null check --- CMakeLists.txt | 2 +- include/blt/std/memory.h | 23 +++++++++++++---------- libraries/parallel-hashmap | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6219477..58beada 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) 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_TARGET BLT) diff --git a/include/blt/std/memory.h b/include/blt/std/memory.h index b13adea..164e2da 100644 --- a/include/blt/std/memory.h +++ b/include/blt/std/memory.h @@ -468,20 +468,23 @@ namespace blt size = std::max(size_, size); size = blt::mem::next_byte_allocation(size); T* new_buffer = new T[size]; - if constexpr (std::is_trivially_copyable_v) + if (buffer_ != nullptr) { - std::memcpy(new_buffer, buffer_, size_ * sizeof(T)); - } else - { - if constexpr (std::is_copy_constructible_v && !std::is_move_constructible_v) + if constexpr (std::is_trivially_copyable_v) { - for (size_t i = 0; i < size_; i++) - new_buffer[i] = T(buffer_[i]); + std::memcpy(new_buffer, buffer_, size_ * sizeof(T)); } else - for (size_t i = 0; i < size_; i++) - new_buffer[i] = std::move(buffer_[i]); + { + if constexpr (std::is_copy_constructible_v && !std::is_move_constructible_v) + { + 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; size_ = size; } diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index d88c5e1..1036816 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit d88c5e15079047777b418132ece5879e7c9aaa2b +Subproject commit 10368163ab1f4367d2f0685b5928b1c973ebd1ec