summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/conts/vec.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/include/conts/vec.h b/include/conts/vec.h
index 8da77cf..19fd18f 100644
--- a/include/conts/vec.h
+++ b/include/conts/vec.h
@@ -24,6 +24,9 @@ struct VEC_STRUCT {
static inline struct VEC_STRUCT VEC(create)(size_t reserve)
{
+ if (reserve == 0)
+ return (struct VEC_STRUCT) {.n = 0, .s = 0, .buf = NULL};
+
return (struct VEC_STRUCT) {
.n = 0,
.s = reserve,
@@ -96,7 +99,7 @@ static inline void VEC(reserve)(struct VEC_STRUCT *v, size_t n)
return;
while (v->s < v->n)
- v->s *= 2;
+ v->s = v->s == 0 ? 1 : 2 * v->s;
v->buf = realloc(v->buf, v->s * sizeof(VEC_TYPE));
}