From 35759fe54afef2015685e004dfe76ff79c27e32e Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Tue, 26 Sep 2023 15:59:21 -0400 Subject: minimum reserve size is two and invalid assert --- src/dynamic-array.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dynamic-array.hpp') diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index f06ddac..6b22f6b 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -116,7 +116,7 @@ template inline bool DynArray::Has(const T &val) { template inline void DynArray::Push(const T &val) { if (this->elementCount + 1 > this->reservedCount) { - auto safeReserveCount = this->reservedCount == 0 ? 1 : this->reservedCount; + auto safeReserveCount = this->reservedCount < 2 ? 2 : this->reservedCount; DynArrayReserve(this, int64_t(safeReserveCount * 1.5)); } auto itemPtr = this->ptr + (sizeof(T) * this->elementCount); @@ -126,7 +126,7 @@ template inline void DynArray::Push(const T &val) { } template inline T DynArray::Pop() { - assert(this->elementCount == 0 && "Invalid DynArray::Pop() - Contains no elements"); + assert(this->elementCount > 0 && "Invalid DynArray::Pop() - Contains no elements"); this->elementCount -= 1; return *reinterpret_cast((this->ptr + (sizeof(T) * this->elementCount))); } -- cgit v1.2.3