diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-12-24 03:28:28 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-12-24 03:28:28 +0100 |
commit | d9cc1bc940ad0e4d2852bd95d1c2ccd0d8ddaf36 (patch) | |
tree | e83c0600a4cc55d81fa853678c76a84ff35fe723 /src | |
parent | 1c5846378bf832562b7cc2eb782a743ec9cd32f5 (diff) |
Fix weird edge-case when cap == 1 and gf == 1.5f
Diffstat (limited to 'src')
-rw-r--r-- | src/gevector.h | 13 |
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; \ |