summaryrefslogtreecommitdiff
path: root/src/vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vector.c')
-rw-r--r--src/vector.c39
1 files changed, 23 insertions, 16 deletions
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 <s.h>
#include <assert.h>
#include <errno.h>
-#include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#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;