summaryrefslogtreecommitdiff
path: root/src/dynamic-array.hpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2024-01-01 18:53:01 -0500
committerJonathan Bradley <jcb@pikum.xyz>2024-01-01 18:53:01 -0500
commit5e255ce57f75acda03a0ff5103767f9cb5334396 (patch)
tree4c46e2f626dacd295618ef6c1bfbdaf12b9291de /src/dynamic-array.hpp
parentb380281d1235ed6a4c6e271bd0c53d393f14b394 (diff)
DynArray resize should destruct valid elements
Diffstat (limited to 'src/dynamic-array.hpp')
-rw-r--r--src/dynamic-array.hpp5
1 files changed, 3 insertions, 2 deletions
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 <typename T> inline void DynArray<T>::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<T *>(this->ptr + (i * sizeof(T)))->~T();
+ for (int64_t i = beforeCount - 1; i >= count; --i) {
+ T *ptr = reinterpret_cast<T *>(this->ptr + (i * sizeof(T)));
+ ptr->~T();
}
}
}