aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-03-18 21:32:58 +0800
committerMistivia <i@mistivia.com>2025-03-18 21:32:58 +0800
commitafb5ae7905c666eb259288ba0d3b47f71a13958f (patch)
tree9d754a68179a4b7736f3d02f9a5dd5a910c65841 /src/utils.c
parentc684a4a302e95d860210a9ddaa891adf9775eadc (diff)
add parser unit test
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 354159b..1baf283 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,5 +1,8 @@
#include "utils.h"
+#include <stdio.h>
+#include <assert.h>
+
struct allocator {
void** bufs;
size_t cap;
@@ -19,10 +22,12 @@ void deleteAllocator(Allocator alct) {
for (size_t i = 0; i < alct->len; i++) {
free(alct->bufs[i]);
}
+ free(alct->bufs);
free(alct);
}
void * allocate(Allocator alct, size_t size) {
+ assert(size > 0);
if (alct->len >= alct->cap) {
alct->cap = alct->cap * 2; // Doubling the capacity
alct->bufs = realloc(alct->bufs, sizeof(void*) * alct->cap);