From: Kevin Day Date: Sun, 6 Aug 2023 00:38:12 +0000 (-0500) Subject: Regression: Invalid type used when allocating string, f_string_t should instead be... X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=12d2035796d530ccba153da718ef656859f40682;p=fll Regression: Invalid type used when allocating string, f_string_t should instead be f_char_t. I noticed odd differences between the 0.6.x and the 0.7.x in terms of memory usage. I discovered this to be due to a bug where the f_string_t is being used when the type should be instead f_char_t. This is likely a bug introduced in some past refactor. --- diff --git a/level_0/f_string/c/private-string.c b/level_0/f_string/c/private-string.c index 58080d5..f055681 100644 --- a/level_0/f_string/c/private-string.c +++ b/level_0/f_string/c/private-string.c @@ -10,7 +10,7 @@ extern "C" { f_status_t private_f_string_append(const f_string_t source, const f_number_unsigned_t length, f_string_dynamic_t * const destination) { { - const f_status_t status = f_memory_array_increase_by(length + 1, sizeof(f_string_t), (void **) &destination->string, &destination->used, &destination->size); + const f_status_t status = f_memory_array_increase_by(length + 1, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); if (F_status_is_error(status)) return status; } @@ -38,7 +38,7 @@ extern "C" { if (size + 1 > F_string_t_size_d) return F_status_set_error(F_string_too_large); - status = f_memory_array_increase_by(size + 1, sizeof(f_string_t), (void **) &destination->string, &destination->used, &destination->size); + status = f_memory_array_increase_by(size + 1, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); if (F_status_is_error(status)) return status; f_number_unsigned_t first = 0; @@ -81,7 +81,7 @@ extern "C" { if (destination->used + length + 1 > F_string_t_size_d) return F_status_set_error(F_string_too_large); { - const f_status_t status = f_memory_array_increase_by(length + 1, sizeof(f_string_t), (void **) &destination->string, &destination->used, &destination->size); + const f_status_t status = f_memory_array_increase_by(length + 1, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); if (F_status_is_error(status)) return status; } @@ -116,7 +116,7 @@ extern "C" { if (i > first) { size = i - first; - status = f_memory_array_increase_by(size + 1, sizeof(f_string_t), (void **) &destination->string, &destination->used, &destination->size); + status = f_memory_array_increase_by(size + 1, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); if (F_status_is_error(status)) return status; memmove(destination->string + offset + size, destination->string + offset, sizeof(f_char_t) * (destination->used - offset)); @@ -134,7 +134,7 @@ extern "C" { if (i > first) { size = i - first; - status = f_memory_array_increase_by(size + 1, sizeof(f_string_t), (void **) &destination->string, &destination->used, &destination->size); + status = f_memory_array_increase_by(size + 1, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); if (F_status_is_error(status)) return status; memmove(destination->string + offset + size, destination->string + offset, sizeof(f_char_t) * (destination->used - offset)); diff --git a/level_0/f_string/c/string/dynamic.c b/level_0/f_string/c/string/dynamic.c index 2e59c70..14d95c5 100644 --- a/level_0/f_string/c/string/dynamic.c +++ b/level_0/f_string/c/string/dynamic.c @@ -12,7 +12,7 @@ extern "C" { if (!structure) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return f_memory_array_adjust(length, sizeof(f_string_t), (void **) &structure->string, &structure->used, &structure->size); + return f_memory_array_adjust(length, sizeof(f_char_t), (void **) &structure->string, &structure->used, &structure->size); } #endif // _di_f_string_dynamic_adjust_ @@ -110,7 +110,7 @@ extern "C" { if (!structure) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return f_memory_array_decimate_by(amount, sizeof(f_string_t), (void **) &structure->string, &structure->used, &structure->size); + return f_memory_array_decimate_by(amount, sizeof(f_char_t), (void **) &structure->string, &structure->used, &structure->size); } #endif // _di_f_string_dynamic_decimate_by_ @@ -120,7 +120,7 @@ extern "C" { if (!structure) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return f_memory_array_decrease_by(amount, sizeof(f_string_t), (void **) &structure->string, &structure->used, &structure->size); + return f_memory_array_decrease_by(amount, sizeof(f_char_t), (void **) &structure->string, &structure->used, &structure->size); } #endif // _di_f_string_dynamic_decrease_by_ @@ -130,7 +130,7 @@ extern "C" { if (!structure) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return f_memory_array_increase(step, sizeof(f_string_t), (void **) &structure->string, &structure->used, &structure->size); + return f_memory_array_increase(step, sizeof(f_char_t), (void **) &structure->string, &structure->used, &structure->size); } #endif // _di_f_string_dynamic_increase_ @@ -140,7 +140,7 @@ extern "C" { if (!structure) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return f_memory_array_increase_by(amount, sizeof(f_string_t), (void **) &structure->string, &structure->used, &structure->size); + return f_memory_array_increase_by(amount, sizeof(f_char_t), (void **) &structure->string, &structure->used, &structure->size); } #endif // _di_f_string_dynamic_increase_by_ @@ -614,7 +614,7 @@ extern "C" { if (!structure) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return f_memory_array_resize(length, sizeof(f_string_t), (void **) &structure->string, &structure->used, &structure->size); + return f_memory_array_resize(length, sizeof(f_char_t), (void **) &structure->string, &structure->used, &structure->size); } #endif // _di_f_string_dynamic_resize_ @@ -693,7 +693,7 @@ extern "C" { if (destination->used == F_string_t_size_d) return F_status_set_error(F_string_too_large); { - const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_string_t), (void **) &destination->string, &destination->used, &destination->size); + const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); if (F_status_is_error(status)) return status; } @@ -716,7 +716,7 @@ extern "C" { if (destination->used == F_string_t_size_d) return F_status_set_error(F_string_too_large); { - const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_string_t), (void **) &destination->string, &destination->used, &destination->size); + const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); if (F_status_is_error(status)) return status; } diff --git a/level_0/f_string/c/string/private-dynamics.c b/level_0/f_string/c/string/private-dynamics.c index b36949b..5b685d8 100644 --- a/level_0/f_string/c/string/private-dynamics.c +++ b/level_0/f_string/c/string/private-dynamics.c @@ -14,7 +14,7 @@ extern "C" { for (f_number_unsigned_t i = length; i < structure->size; ++i) { - status = f_memory_array_adjust(0, sizeof(f_string_t), (void **) &structure->array[i].string, &structure->array[i].used, &structure->array[i].size); + status = f_memory_array_adjust(0, sizeof(f_char_t), (void **) &structure->array[i].string, &structure->array[i].used, &structure->array[i].size); if (F_status_is_error(status)) return status; } // for diff --git a/level_0/f_string/c/string/private-map_multis.c b/level_0/f_string/c/string/private-map_multis.c index 8001b1b..f607bbd 100644 --- a/level_0/f_string/c/string/private-map_multis.c +++ b/level_0/f_string/c/string/private-map_multis.c @@ -15,7 +15,7 @@ extern "C" { for (f_number_unsigned_t i = length; i < structure->size; ++i) { - status = f_memory_array_adjust(0, sizeof(f_string_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); + status = f_memory_array_adjust(0, sizeof(f_char_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); if (F_status_is_error(status)) return status; status = private_f_string_dynamics_adjust(0, &structure->array[i].value); @@ -63,7 +63,7 @@ extern "C" { for (f_number_unsigned_t i = length; i < structure->size; ++i) { - status = f_memory_array_resize(0, sizeof(f_string_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); + status = f_memory_array_resize(0, sizeof(f_char_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); if (F_status_is_error(status)) return status; status = private_f_string_dynamics_resize(0, &structure->array[i].value); diff --git a/level_0/f_string/c/string/private-maps.c b/level_0/f_string/c/string/private-maps.c index f02f0d6..f52e9d8 100644 --- a/level_0/f_string/c/string/private-maps.c +++ b/level_0/f_string/c/string/private-maps.c @@ -14,10 +14,10 @@ extern "C" { for (f_number_unsigned_t i = length; i < structure->size; ++i) { - status = f_memory_array_adjust(0, sizeof(f_string_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); + status = f_memory_array_adjust(0, sizeof(f_char_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); if (F_status_is_error(status)) return status; - status = f_memory_array_adjust(0, sizeof(f_string_t), (void **) &structure->array[i].value.string, &structure->array[i].value.used, &structure->array[i].value.size); + status = f_memory_array_adjust(0, sizeof(f_char_t), (void **) &structure->array[i].value.string, &structure->array[i].value.used, &structure->array[i].value.size); if (F_status_is_error(status)) return status; } // for @@ -62,10 +62,10 @@ extern "C" { for (f_number_unsigned_t i = length; i < structure->size; ++i) { - status = f_memory_array_resize(0, sizeof(f_string_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); + status = f_memory_array_resize(0, sizeof(f_char_t), (void **) &structure->array[i].name.string, &structure->array[i].name.used, &structure->array[i].name.size); if (F_status_is_error(status)) return status; - status = f_memory_array_resize(0, sizeof(f_string_t), (void **) &structure->array[i].value.string, &structure->array[i].value.used, &structure->array[i].value.size); + status = f_memory_array_resize(0, sizeof(f_char_t), (void **) &structure->array[i].value.string, &structure->array[i].value.used, &structure->array[i].value.size); if (F_status_is_error(status)) return status; } // for diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index 335569b..4d011f7 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -301,7 +301,7 @@ extern "C" { // There is no reason to include "." and ".." in the directory listing. if (!strncmp(name_directory.string, "..", 3) || !strncmp(name_directory.string, ".", 2)) { - f_memory_resize(1, 0, sizeof(f_string_t), (void **) & entity[i]); + f_memory_resize(1, 0, sizeof(f_char_t), (void **) & entity[i]); continue; } diff --git a/level_2/fll_execute/c/private-execute.c b/level_2/fll_execute/c/private-execute.c index 7fcc9d1..f834dc7 100644 --- a/level_2/fll_execute/c/private-execute.c +++ b/level_2/fll_execute/c/private-execute.c @@ -553,7 +553,7 @@ extern "C" { void private_fll_execute_path_arguments_fixate(const f_string_static_t program_path, const f_string_statics_t arguments, const f_string_t last_slash, const bool fixated_is, f_string_static_t program_name, f_string_t fixed_arguments[]) { memset(program_name.string, 0, sizeof(f_char_t) * (program_name.used + 1)); - memset(fixed_arguments, 0, sizeof(f_string_t) * (arguments.used + 2)); + memset(fixed_arguments, 0, sizeof(f_char_t) * (arguments.used + 2)); memcpy(program_name.string, last_slash ? last_slash + 1 : program_path.string, sizeof(f_char_t) * program_name.used);