From 3f258f319d92376fabf563c6181b0aeb374f9b74 Mon Sep 17 00:00:00 2001 From: Quinn Date: Fri, 14 Feb 2025 01:31:22 +0100 Subject: [PATCH] fix: if capacity of the dynarr is 0, the capacity is unable to grow --- src/util/dynarr.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/dynarr.h b/src/util/dynarr.h index 76237fc..c92ee0b 100644 --- a/src/util/dynarr.h +++ b/src/util/dynarr.h @@ -48,7 +48,8 @@ DYNARR_LINKAGE uint8_t DYNARR_add(DYNARR_NAME* arr, DYNARR_TYPE item) { // resize the dynamic array if the new count has hit the max capacity if (arr->cap == arr->count) { - arr->cap *= 2; + if (!arr->cap) arr->cap = 1; // set the capacity to 1 if it's 0 + else arr->cap *= 2; // otherwise, multiply the capacity by 2 DYNARR_TYPE* nptr = realloc(arr->dat, arr->cap * sizeof(DYNARR_TYPE)); if (nptr == NULL)