]> Kevux Git Server - fll/commitdiff
Regression: Pre-allocate is using the wrong array.
authorKevin Day <thekevinday@gmail.com>
Wed, 20 Jul 2022 02:04:50 +0000 (21:04 -0500)
committerKevin Day <thekevinday@gmail.com>
Wed, 20 Jul 2022 02:04:50 +0000 (21:04 -0500)
I mixed up the arrays, the code managed to compile, and the error went unnoticed.

The problem is introduced by this commit: 99e025d4b5b1110733e4049416d848f8bc632fb3.

level_3/fake/c/private-make-operate.c

index 162d0a5d639fc87be04b1708190f49c0376a8a62..b713c00f987c412ccff9158ebb08548326095686 100644 (file)
@@ -178,6 +178,7 @@ extern "C" {
     f_array_length_t k = 0;
     f_array_length_t l = 0;
     f_array_length_t m = 0;
+    f_array_length_t n = 0;
 
     const f_string_static_t reserved_name[] = {
       fake_make_parameter_variable_build_s,
@@ -441,13 +442,16 @@ extern "C" {
                 if (content.array[i].start == iki_data->variable.array[0].start && content.array[i].stop == iki_data->variable.array[0].stop || quotes.array[i]) {
 
                   // Pre-allocate memory to reduce number of allocations.
-                  m = parameter->array[k].value.used;
+                  l = parameter->used;
 
-                  for (l = 0; l < parameter->array[k].value.used; ++l) {
-                    m += parameter->array[k].value.array[l].used;
+                  for (m = 0; m < parameter->used; ++m) {
+
+                    for (n = 0; n < parameter->array[m].value.used; ++n) {
+                      l += parameter->array[m].value.array[n].used;
+                    } // for
                   } // for
 
-                  *status = f_string_dynamic_increase_by(m, &data_make->cache_arguments.array[data_make->cache_arguments.used]);
+                  *status = f_string_dynamic_increase_by(l, &data_make->cache_arguments.array[data_make->cache_arguments.used]);
 
                   if (F_status_is_error(*status)) {
                     fll_error_print(data_make->error, F_status_set_fine(*status), "f_string_dynamic_increase_by", F_true);
@@ -533,13 +537,16 @@ extern "C" {
 
                   // Pre-allocate memory to reduce number of allocations.
                   if (quotes.array[i]) {
-                    m = parameter->array[k].value.used;
+                    l = parameter->used;
+
+                    for (m = 0; m < parameter->used; ++m) {
 
-                    for (l = 0; l < parameter->array[k].value.used; ++l) {
-                      m += parameter->array[k].value.array[l].used;
+                      for (n = 0; n < parameter->array[m].value.used; ++n) {
+                        l += parameter->array[m].value.array[n].used;
+                      } // for
                     } // for
 
-                    *status = f_string_dynamic_increase_by(m, &data_make->cache_arguments.array[data_make->cache_arguments.used]);
+                    *status = f_string_dynamic_increase_by(l, &data_make->cache_arguments.array[data_make->cache_arguments.used]);
 
                     if (F_status_is_error(*status)) {
                       fll_error_print(data_make->error, F_status_set_fine(*status), "f_string_dynamic_increase_by", F_true);