summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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; \