From 7d611777a78b9523c669add27d9c4f8b259e9c98 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 11 Aug 2023 22:29:35 -0500 Subject: [PATCH] Bugfix: Stop using f_memory_array_append_all() for an array of IKI data. There is some logic mistake, structural mistake, design mistake, or an oversight. Just do not use it for now and instead use a traditional for loop. I may get rid of f_memory_array_append_all() in the future or I may spend time investigating what my mistake is in this use case. --- level_0/f_iki/c/iki/private-data.c | 56 ++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/level_0/f_iki/c/iki/private-data.c b/level_0/f_iki/c/iki/private-data.c index d24edb4..b9ab34a 100644 --- a/level_0/f_iki/c/iki/private-data.c +++ b/level_0/f_iki/c/iki/private-data.c @@ -46,8 +46,11 @@ extern "C" { } if (source.delimits.used) { - status = f_memory_array_append_all((const void *) &source.delimits.array, source.delimits.used, sizeof(f_number_unsigned_t), (void **) &destination->array[destination->used].delimits.array, &destination->array[destination->used].delimits.used, &destination->array[destination->used].delimits.size); - if (F_status_is_error(status)) return status; + for (f_number_unsigned_t i = 0; i < source.delimits.used; ++i) { + + status = f_memory_array_append(source.delimits.array + i, sizeof(f_number_unsigned_t), (void **) &destination->array[destination->used].delimits.array, &destination->array[destination->used].delimits.used, &destination->array[destination->used].delimits.size); + if (F_status_is_error(status)) return status; + } // for } if (source.variable.used) { @@ -72,33 +75,38 @@ extern "C" { f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_iki_data_t), (void **) &destination->array, &destination->used, &destination->size); if (F_status_is_error(status)) return status; - for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { + { + f_number_unsigned_t j = 0; - destination->array[destination->used].content.used = 0; - destination->array[destination->used].delimits.used = 0; - destination->array[destination->used].variable.used = 0; - destination->array[destination->used].vocabulary.used = 0; + for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { - if (source.array[i].content.used) { - status = f_string_ranges_append_all(source.array[i].content, &destination->array[destination->used].content); - if (F_status_is_error(status)) return status; - } + destination->array[destination->used].content.used = 0; + destination->array[destination->used].delimits.used = 0; + destination->array[destination->used].variable.used = 0; + destination->array[destination->used].vocabulary.used = 0; - if (source.array[i].delimits.used) { - status = f_memory_array_append_all((const void *) &source.array[i].delimits.array, source.array[i].delimits.used, sizeof(f_number_unsigned_t), (void **) &destination->array[destination->used].delimits.array, &destination->array[destination->used].delimits.used, &destination->array[destination->used].delimits.size); - if (F_status_is_error(status)) return status; - } + if (source.array[i].content.used) { + status = f_string_ranges_append_all(source.array[i].content, &destination->array[destination->used].content); + if (F_status_is_error(status)) return status; + } - if (source.array[i].variable.used) { - status = f_string_ranges_append_all(source.array[i].variable, &destination->array[destination->used].variable); - if (F_status_is_error(status)) return status; - } + for (j = 0; j < source.array[i].delimits.used; ++j) { - if (source.array[i].vocabulary.used) { - status = f_string_ranges_append_all(source.array[i].vocabulary, &destination->array[destination->used].vocabulary); - if (F_status_is_error(status)) return status; - } - } // for + status = f_memory_array_append(source.array[i].delimits.array + j, sizeof(f_number_unsigned_t), (void **) &destination->array[destination->used].delimits.array, &destination->array[destination->used].delimits.used, &destination->array[destination->used].delimits.size); + if (F_status_is_error(status)) return status; + } // for + + if (source.array[i].variable.used) { + status = f_string_ranges_append_all(source.array[i].variable, &destination->array[destination->used].variable); + if (F_status_is_error(status)) return status; + } + + if (source.array[i].vocabulary.used) { + status = f_string_ranges_append_all(source.array[i].vocabulary, &destination->array[destination->used].vocabulary); + if (F_status_is_error(status)) return status; + } + } // for + } return F_none; } -- 1.8.3.1