From d9cc1bc940ad0e4d2852bd95d1c2ccd0d8ddaf36 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 24 Dec 2022 03:28:28 +0100 Subject: Fix weird edge-case when cap == 1 and gf == 1.5f --- src/gevector.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') 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; \ -- cgit v1.2.3