diff options
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -188,10 +188,16 @@ void grow_memory_block(struct memory_block *a, int amount) a->size += amount; if (a->size >= a->capacity) { new_cap = a->capacity; - if (new_cap == 0) { - new_cap = 8; - } else { - new_cap *= 2; + while (new_cap < a->size) { + if (new_cap == 0) { + new_cap = 8; + } else { + new_cap *= 2; + } + if (new_cap < 0) { // Overflow + fprintf(stderr, "Memory block too large."); + abort(); + } } a->ptr = (char *)realloc(a->ptr, new_cap); a->capacity = new_cap; |