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 --- CMakeLists.txt | 2 +- src/util/util.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db233da..bf4279e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories(kalmia PUBLIC include 3rdparty 3rdparty/ezxml) if (UNIX) set_target_properties( kalmia PROPERTIES - C_STANDARD 99 + C_STANDARD 90 CMAKE_C_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wpedantic" ) endif() 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