From 44d56f5311f98a8955c67638e7520963dbd4d845 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 12 Jan 2025 00:14:03 -0300 Subject: Revamp lib, simplify it a bit and address some FIXMEs --- src/vector.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'src/vector.c') diff --git a/src/vector.c b/src/vector.c index 385e600..2736820 100644 --- a/src/vector.c +++ b/src/vector.c @@ -1,19 +1,16 @@ -#include "config.h" +#include #include #include -#include #include #include #include #include #include -#include "catalog.h" #include "i18n.h" #include "logerr.h" #include "math.h" -#include "util.h" #include "vector.h" @@ -55,11 +52,8 @@ vector_new_with( assert(capacity > 0); if (capacity > max_capacity) { - logerr( - _(MSG_ERR_VECTOR_MAX_CAPACITY), - max_capacity, - strerror(EOVERFLOW) - ); + const char *const s = _(MSG_ERR_VECTOR_MAX_CAPACITY); + logerr(s, max_capacity, strerror(EOVERFLOW)); rc = EOVERFLOW; goto out; } @@ -90,10 +84,12 @@ vector_new_with( out: if (rc) { if (ret != NULL) { - freeit((void *)&ret); + free((struct Vector *)ret); + ret = NULL; } if (values != NULL) { - freeit((void *)&values); + free((struct Vector *)values); + values = NULL; } } return rc; @@ -121,8 +117,10 @@ vector_free(const struct Vector **const v) { } const void **values = (*v)->values; - freeit((void *)&values); - freeit((void *)v); + free(values); + values = NULL; + free((struct Vector *)(*v)); + *v = NULL; } size_t @@ -146,12 +144,20 @@ next_capacity(const struct Vector *const v) { } static int -next_size(const struct Vector *const v, const size_t capacity, size_t *const out) { +next_size( + const struct Vector *const v, + const size_t capacity, + size_t *const out +) { return mul_size(v->value_size, capacity, out); } int -vector_nth(const struct Vector *const v, const size_t idx, const void **const out) { +vector_nth( + const struct Vector *const v, + const size_t idx, + const void **const out +) { int rc = -1; const size_t count = vector_count(v); @@ -232,7 +238,8 @@ vector_push_back(const struct Vector *const v, const void *const value) { out: if (rc) { if (new_values != NULL) { - freeit((void *)&new_values); + free(new_values); + new_values = NULL; } } return rc; -- cgit v1.2.3