From 6ed18ee1677007b9870fad63b8ef11e7d9afe0d9 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sun, 21 Aug 2022 10:07:29 +0200 Subject: Work around void * arithmetic errors ...but the data structure should probably be reworked instead of relying on the optional uintptr_t type :-/ --- src/config.c | 4 ++-- src/util/string.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/config.c b/src/config.c index bc7c28b..997a53c 100644 --- a/src/config.c +++ b/src/config.c @@ -7,6 +7,7 @@ #include #include #include +#include /******************************************************************************/ @@ -118,8 +119,7 @@ void sk_config_cpy(struct sk_config *restrict dest, const struct sk_config *rest size_t last = 0; while (src->global.conf_dir[last] != NULL) last++; last--; - char *end = src->global.conf_dir[last] + strlen(src->global.conf_dir[last]); - size_t bufsz = (void *)end - (void *)src->global.conf_dir; + size_t bufsz = ((uintptr_t)src->global.conf_dir[last] - (uintptr_t)src->global.conf_dir) + strlen(src->global.conf_dir[last]) * sizeof(char); void *dbuf = malloc(bufsz); memcpy(dbuf, src->global.conf_dir, bufsz); diff --git a/src/util/string.c b/src/util/string.c index d5ad73b..c760b06 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -4,6 +4,8 @@ #include #include +#include + #ifndef HAVE_STRDUP char *strdup(const char *s) { if (NULL == s) { @@ -143,12 +145,12 @@ size_t strsplit(const char *restrict in, const char *restrict sep, void *buf) { if (arr) { /* update array pointers */ for (int j = 0; j < i; j++) { - arr[j] = (char *)((size_t)buf + strtokoffset + (size_t)arr[j]); + arr[j] = (char *)((uintptr_t)buf + strtokoffset + (size_t)arr[j]); } arr[i] = NULL; /* NULL termination */ /* copy tokenized string from tmp to the back of buf */ - (void)memcpy(buf + strtokoffset, tmp, strtoklen); + (void)memcpy((void *)((uintptr_t)buf + strtokoffset), tmp, strtoklen); } free(tmp); -- cgit v1.2.3