summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-01-05 09:23:50 -0600
committersanine <sanine.not@pm.me>2023-01-05 09:23:50 -0600
commita18d004be2217bd59c34ba5a3600f72de70c9419 (patch)
tree350106c457aaedef905843f15a9119d009513738
parent1b62e92bcc18762a8e4a2e9e4dc322705bfb7eec (diff)
revert to pure C89
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/util/util.c13
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<count; i++) {
+ int i;
+ for (i=0; i<count; i++) {
dest[i] = KA_STR_TO_REAL(nptr, &end);
if (nptr == end) {
result -= 1;
@@ -49,7 +51,8 @@ size_t kai_text_to_longs(long *dest, const char *str, size_t count)
size_t result = count;
- for (int i=0; i<count; i++) {
+ int i;
+ for (i=0; i<count; i++) {
dest[i] = strtol(nptr, &end, 10);
if (nptr == end) {
result -= 1;