From 5df2bcfe39f124451480cb3bc4c094c00392490f Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 9 Sep 2020 20:44:04 -0400 Subject: Fix change reallocarray calls to realloc The reallocarray calls were returning pointers that produced a segfault when dereferenced, not sure why but realloc seems to fix the issue. --- collections/vector/vector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'collections/vector/vector.c') diff --git a/collections/vector/vector.c b/collections/vector/vector.c index f14c302..d87ae76 100644 --- a/collections/vector/vector.c +++ b/collections/vector/vector.c @@ -79,7 +79,7 @@ vec *root; if (!root) return; - root->base = reallocarray(root->base, root->limit * 2, sizeof(void*)); + root->base = realloc(root->base, root->limit * 2 * sizeof(void*)); assert(root->base); } @@ -261,7 +261,7 @@ int n; for (i = root->limit; i < root->end + n; i*=2); - root->base = reallocarray(root->base, i, sizeof(void*)); + root->base = realloc(root->base, i * sizeof(void*)); } void vec_clear(root) -- cgit v1.1 From d9e662b23f8c300288ccc09e2350c666c047d596 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 9 Sep 2020 20:47:45 -0400 Subject: Fix vector was not increasing its limit when resized --- collections/vector/vector.c | 1 + 1 file changed, 1 insertion(+) (limited to 'collections/vector/vector.c') diff --git a/collections/vector/vector.c b/collections/vector/vector.c index d87ae76..d40959d 100644 --- a/collections/vector/vector.c +++ b/collections/vector/vector.c @@ -81,6 +81,7 @@ vec *root; root->base = realloc(root->base, root->limit * 2 * sizeof(void*)); assert(root->base); + root->limit *= 2; } vec* vec_cp(root) -- cgit v1.1 From 4e1c2be8b650a9ea13f56565deb407a8e9164d62 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 9 Sep 2020 20:49:32 -0400 Subject: Fix printf formatters for debug print --- collections/vector/vector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'collections/vector/vector.c') diff --git a/collections/vector/vector.c b/collections/vector/vector.c index d40959d..153cf9f 100644 --- a/collections/vector/vector.c +++ b/collections/vector/vector.c @@ -17,8 +17,8 @@ vec *root; { int i; - fprintf(stderr, "VEC[base: %p, end: %p, limit:%p]:\n\t ", - root->base, root->end, root->limit); + fprintf(stderr, "VEC[base: %p, end: %d, limit:%d]:\n\t ", + (void*) root->base, root->end, root->limit); for (i=0; i < root->end; i++){ fprintf(stderr, "[%p]", vec_index(root,i)); } -- cgit v1.1