From 5e255ce57f75acda03a0ff5103767f9cb5334396 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Mon, 1 Jan 2024 18:53:01 -0500 Subject: DynArray resize should destruct valid elements --- src/dynamic-array.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/dynamic-array.hpp') diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index d35e5e2..039dcd0 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -208,8 +208,9 @@ template inline void DynArray::Resize(int64_t count) { int64_t beforeCount = this->elementCount; if IS_DESTRUCTIBLE(T) { if (beforeCount > count) { - for (int64_t i = beforeCount; i > count; --i) { - reinterpret_cast(this->ptr + (i * sizeof(T)))->~T(); + for (int64_t i = beforeCount - 1; i >= count; --i) { + T *ptr = reinterpret_cast(this->ptr + (i * sizeof(T))); + ptr->~T(); } } } -- cgit v1.2.3