summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-24 03:28:28 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-24 03:28:28 +0100
commitd9cc1bc940ad0e4d2852bd95d1c2ccd0d8ddaf36 (patch)
treee83c0600a4cc55d81fa853678c76a84ff35fe723
parent1c5846378bf832562b7cc2eb782a743ec9cd32f5 (diff)
Fix weird edge-case when cap == 1 and gf == 1.5f
-rw-r--r--src/gevector.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/gevector.h b/src/gevector.h
index dc700e1..6827e66 100644
--- a/src/gevector.h
+++ b/src/gevector.h
@@ -39,11 +39,14 @@
int \
n##_insert(struct n *vec, t item, size_t i) \
{ \
- if (vec->size == vec->capacity \
- && n##_resize(vec, (size_t) (vec->capacity \
- * vec->gfactor)) \
- == -1) \
- return -1; \
+ if (vec->size == vec->capacity) { \
+ size_t new_capacity = \
+ (size_t) (vec->capacity * vec->gfactor); \
+ if (new_capacity == vec->capacity) \
+ new_capacity++; \
+ if (n##_resize(vec, new_capacity) == -1) \
+ return -1; \
+ } \
for (size_t j = vec->size; j > i; j--) \
vec->items[j] = vec->items[j - 1]; \
vec->items[i] = item; \