From 8142cbb3d1a926d5c8cb5c59a0ea259948c59ad1 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Wed, 29 Nov 2023 21:00:12 -0500 Subject: DynArray::Reserve should only run destructor on elements that actually exist --- src/dynamic-array.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/dynamic-array.hpp') diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index 6813edf..876f71d 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -195,8 +195,10 @@ template inline void DynArray::Reserve(int64_t count) { template inline void DynArray::Resize(int64_t count) { int64_t beforeCount = this->elementCount; if IS_DESTRUCTIBLE(T) { - for (long i = count; i > beforeCount; --i) { - reinterpret_cast(this->ptr + (i * sizeof(T)))->~T(); + if (beforeCount > count) { + for (long i = count; i > beforeCount; --i) { + reinterpret_cast(this->ptr + (i * sizeof(T)))->~T(); + } } } if (count > 0) { -- cgit v1.2.3