diff options
author | sanine <sanine.not@pm.me> | 2023-01-05 09:23:50 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-01-05 09:23:50 -0600 |
commit | a18d004be2217bd59c34ba5a3600f72de70c9419 (patch) | |
tree | 350106c457aaedef905843f15a9119d009513738 /src/util | |
parent | 1b62e92bcc18762a8e4a2e9e4dc322705bfb7eec (diff) |
revert to pure C89
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/util.c | 13 |
1 files changed, 8 insertions, 5 deletions
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; |