summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-05-31 14:57:18 -0300
committerEuAndreh <eu@euandre.org>2024-05-31 14:57:18 -0300
commit0d4174849c4336a3e87c25c66b4cea504a7aad12 (patch)
treefe83ddcc9db5b88c7079979c0adadda540a1482c /src
parentsrc/string.h: Add implementation for some basic functions (diff)
downloadpindaiba-0d4174849c4336a3e87c25c66b4cea504a7aad12.tar.gz
pindaiba-0d4174849c4336a3e87c25c66b4cea504a7aad12.tar.xz
src/vector.c: Make the "void **values" `const`
Diffstat (limited to 'src')
-rw-r--r--src/vector.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/vector.c b/src/vector.c
index 358036b..6708546 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -18,7 +18,7 @@
struct Vector {
- void **values;
+ const void **values;
size_t capacity;
size_t count;
const size_t max_capacity;
@@ -46,15 +46,8 @@ vector_new_with(
) {
int rc = -1;
- struct Vector v = {
- .values = NULL,
- .capacity = capacity,
- .count = 0U,
- .max_capacity = max_capacity,
- .multiplier = multiplier,
- .value_size = value_size,
- };
- struct Vector *restrict ret = NULL;
+ const struct Vector *ret = NULL;
+ void *values = NULL;
assert(capacity > 0);
if (capacity > max_capacity) {
@@ -68,8 +61,8 @@ vector_new_with(
}
const size_t array_bytes_size = capacity * value_size;
- v.values = malloc(array_bytes_size);
- if (v.values == NULL) {
+ values = malloc(array_bytes_size);
+ if (values == NULL) {
logerr("malloc(): %s", strerror(errno));
goto out;
}
@@ -79,17 +72,26 @@ vector_new_with(
logerr("malloc(): %s", strerror(errno));
goto out;
}
- memcpy(ret, &v, sizeof(v));
+ memcpy((void *)ret, &(struct Vector) {
+ .values = values,
+ .capacity = capacity,
+ .count = 0U,
+ .max_capacity = max_capacity,
+ .multiplier = multiplier,
+ .value_size = value_size,
+ }, sizeof(*ret));
*out = ret;
rc = 0;
out:
if (rc) {
if (ret != NULL) {
- free(ret);
+ free((void *)ret);
+ ret = NULL;
}
- if (v.values != NULL) {
- free(v.values);
+ if (values != NULL) {
+ free((void *)values);
+ values = NULL;
}
}
return rc;
@@ -196,6 +198,7 @@ out:
if (rc) {
if (new_values != NULL) {
free(new_values);
+ new_values = NULL;
}
}
return rc;