From 7f24621bec0b0a5b3cab9ec2dfc68929a2d49d25 Mon Sep 17 00:00:00 2001 From: comex Date: Sun, 1 Mar 2015 23:07:15 -0500 Subject: A number of critical fixes painstakingly discovered in the slowest way possible. --- lib/cbit/vec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/cbit/vec.c') diff --git a/lib/cbit/vec.c b/lib/cbit/vec.c index 21038a2..2f875ff 100644 --- a/lib/cbit/vec.c +++ b/lib/cbit/vec.c @@ -1,12 +1,16 @@ #include "cbit/vec.h" #include +#include void vec_realloc_internal(struct vec_internal *vi, size_t new_capacity, size_t esize) { + if (new_capacity == 0) + abort(); size_t new_size = safe_mul(new_capacity, esize); if (vi->els == vi->storage) { void *new = malloc(new_size); - memcpy(new, vi->els, vi->capacity * esize); + size_t min_cap = new_capacity < vi->capacity ? new_capacity : vi->capacity; + memcpy(new, vi->els, min_cap * esize); vi->els = new; } else { vi->els = realloc(vi->els, new_size); -- cgit v1.2.3