From a18d004be2217bd59c34ba5a3600f72de70c9419 Mon Sep 17 00:00:00 2001 From: sanine Date: Thu, 5 Jan 2023 09:23:50 -0600 Subject: revert to pure C89 --- src/util/util.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/util') diff --git a/src/util/util.c b/src/util/util.c index 05701c6..00561b7 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -7,15 +7,16 @@ void *kai_expand_array(void **array, size_t *count, size_t element_size) { size_t new_count = *count + 1; size_t new_size = element_size * new_count; - /* cast to uint8_t so we can do pointer arithmetic */ - uint8_t *new_array = realloc(*array, new_size); + /* cast to unsigned char so we can do pointer arithmetic */ + unsigned char *new_array = realloc(*array, new_size); if (new_array == NULL) { fprintf(stderr, "[kalmia] ERROR: failed to add %ul bytes to %ul-byte array!\n", element_size, element_size * *count); return NULL; } - void *new_element = new_array + (*count * element_size); + size_t offset = (*count * element_size) / sizeof(unsigned char); + void *new_element = new_array + offset; *array = new_array; *count = new_count; @@ -30,7 +31,8 @@ size_t kai_text_to_reals(ka_real_t *dest, const char *str, size_t count) size_t result = count; - for (int i=0; i