From: Kevin Day Date: Thu, 3 Dec 2020 01:01:29 +0000 (-0600) Subject: Update: memory changes, memory bugfixes, and minor controller program fixes. X-Git-Tag: 0.5.2~46 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=f1b8c3662cdf3aa657cfb8096b4d56f42de967f7;p=fll Update: memory changes, memory bugfixes, and minor controller program fixes. Do some minor cleanup with the allocation functions. The *_delete_simple() and *_destroy_simple() macros need to always set size to 0, because they are always ignoring the return status. Also move the relating check outside of the for loop for performance reasons. Minor cleanups in memory functions. Add additional parameter checks to the memory create functions. Add additional size and length checks in the memory delete and destroy functions. Fix bug in f_macro_memory_structure_macro_increment() where if condition is obviously wrong (two '>' checks are used against each other!). Change behavior to increment against "used" instead of "size", more consistently. Rewrite the *_increase() and *_increase_by() functions due to bugs and inconsistencies. Only use variables when needed for performance and resource reasons. Get rid of the F_array_too_large on success behavior as the current design doesn't handle the cases where both F_array_too_large and an error occurs afterwards. Fix mistake in controller program where I forgot to actually set the allocated sizes. Use counter instead of pointer for entry item in controller program. In some cases, use fl_string_dynamic_terminate_after() instead of fl_string_dynamic_terminate() (there will likely be more of these changes). --- diff --git a/level_0/f_fss/c/fss_named.h b/level_0/f_fss/c/fss_named.h index e3a8d1d..1a63dad 100644 --- a/level_0/f_fss/c/fss_named.h +++ b/level_0/f_fss/c/fss_named.h @@ -157,7 +157,7 @@ extern "C" { #define f_macro_fss_nameds_t_delete(status, sets) \ status = F_none; \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_named_t_delete(status, sets.array[sets.used]); \ if (status != F_none) break; \ @@ -174,7 +174,7 @@ extern "C" { #define f_macro_fss_nameds_t_destroy(status, sets) \ status = F_none; \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_named_t_destroy(status, sets.array[sets.used]); \ if (status != F_none) break; \ @@ -192,12 +192,9 @@ extern "C" { while (sets.used > 0) { \ sets.used--; \ f_macro_fss_named_t_delete_simple(sets.array[sets.used]); \ - if (!sets.used) { \ - if (f_memory_delete((void **) & sets.array, sizeof(f_fss_named_t), sets.size)) { \ - sets.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & sets.array, sizeof(f_fss_named_t), sets.size); \ + sets.size = 0; /** * Destroy a fss content sets. @@ -209,12 +206,9 @@ extern "C" { while (sets.used > 0) { \ sets.used--; \ f_macro_fss_named_t_destroy_simple(sets.array[sets.used]); \ - if (!sets.used) { \ - if (f_memory_destroy((void **) & sets.array, sizeof(f_fss_named_t), sets.size)) { \ - sets.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & sets.array, sizeof(f_fss_named_t), sets.size); \ + sets.size = 0; /** * Resize a fss content sets. diff --git a/level_0/f_fss/c/fss_nest.h b/level_0/f_fss/c/fss_nest.h index 3b8af49..f271f8c 100644 --- a/level_0/f_fss/c/fss_nest.h +++ b/level_0/f_fss/c/fss_nest.h @@ -200,7 +200,7 @@ extern "C" { #define f_macro_fss_items_t_delete(status, items) \ status = F_none; \ items.used = items.size; \ - while (items.used > 0) { \ + while (items.used) { \ items.used--; \ f_macro_fss_item_t_delete(status, items.array[items.used]); \ if (status != F_none) break; \ @@ -217,7 +217,7 @@ extern "C" { #define f_macro_fss_items_t_destroy(status, items) \ status = F_none; \ items.used = items.size; \ - while (items.used > 0) { \ + while (items.used) { \ items.used--; \ f_macro_fss_item_t_destroy(status, items.array[items.used]); \ if (status != F_none) break; \ @@ -232,15 +232,12 @@ extern "C" { */ #define f_macro_fss_items_t_delete_simple(items) \ items.used = items.size; \ - while (items.used > 0) { \ + while (items.used) { \ items.used--; \ f_macro_fss_item_t_delete_simple(items.array[items.used]); \ - if (!items.used) { \ - if (f_memory_delete((void **) & items.array, sizeof(f_fss_item_t), items.size)) { \ - items.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & items.array, sizeof(f_fss_item_t), items.size); \ + items.size = 0; /** * Destroy a fss items. @@ -252,12 +249,9 @@ extern "C" { while (items.used > 0) { \ items.used--; \ f_macro_fss_item_t_destroy_simple(status, items.array[items.used]); \ - if (!items.used) { \ - if (f_memory_destroy((void **) & items.array, sizeof(f_fss_item_t), items.size)) { \ - items.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & items.array, sizeof(f_fss_item_t), items.size); \ + items.size = 0; /** * Resize a fss items. @@ -374,7 +368,7 @@ extern "C" { #define f_macro_fss_nest_t_delete(status, nest) \ status = F_none; \ nest.used = nest.size; \ - while (nest.used > 0) { \ + while (nest.used) { \ nest.used--; \ f_macro_fss_items_t_delete(status, nest.depth[nest.used]); \ if (status != F_none) break; \ @@ -391,7 +385,7 @@ extern "C" { #define f_macro_fss_nest_t_destroy(status, nest) \ status = F_none; \ nest.used = nest.size; \ - while (nest.used > 0) { \ + while (nest.used) { \ nest.used--; \ f_macro_fss_items_t_destroy(status, nest.depth[nest.used]); \ if (status != F_none) break; \ @@ -406,15 +400,12 @@ extern "C" { */ #define f_macro_fss_nest_t_delete_simple(nest) \ nest.used = nest.size; \ - while (nest.used > 0) { \ + while (nest.used) { \ nest.used--; \ f_macro_fss_items_t_delete_simple(nest.depth[nest.used]); \ - if (!nest.used) { \ - if (f_memory_delete((void **) & nest.depth, sizeof(f_fss_items_t), nest.size)) { \ - nest.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & nest.depth, sizeof(f_fss_items_t), nest.size); \ + nest.size = 0; /** * Destroy a fss content nest. @@ -426,12 +417,9 @@ extern "C" { while (nest.used > 0) { \ nest.used--; \ f_macro_fss_items_t_destroy_simple(nest.depth[nest.used]); \ - if (!nest.used) { \ - if (f_memory_destroy((void **) & nest.depth, sizeof(f_fss_items_t), nest.size)) { \ - nest.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & nest.depth, sizeof(f_fss_items_t), nest.size); \ + nest.size = 0; /** * Resize a fss content nest. @@ -543,7 +531,7 @@ extern "C" { #define f_macro_fss_nests_t_delete(nests) \ status = F_none; \ nests.used = nests.size; \ - while (nests.used > 0) { \ + while (nests.used) { \ nests.used--; \ f_macro_fss_nest_t_delete(status, nests.array[nests.used]); \ if (status != F_none) break; \ @@ -560,7 +548,7 @@ extern "C" { #define f_macro_fss_nests_t_destroy(nests) \ status = F_none; \ nests.used = nests.size; \ - while (nests.used > 0) { \ + while (nests.used) { \ nests.used--; \ f_macro_fss_nest_t_destroy(status, nests.array[nests.used]); \ if (status != F_none) break; \ @@ -575,15 +563,12 @@ extern "C" { */ #define f_macro_fss_nests_t_delete_simple(nests) \ nests.used = nests.size; \ - while (nests.used > 0) { \ + while (nests.used) { \ nests.used--; \ f_macro_fss_nest_t_delete_simple(nests.array[nests.used]); \ - if (!nests.used) { \ - if (f_memory_delete((void **) & nests.array, sizeof(f_fss_nest_t), nests.size)) { \ - nests.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & nests.array, sizeof(f_fss_nest_t), nests.size); \ + nests.size = 0; /** * Destroy a fss content nests. @@ -592,15 +577,12 @@ extern "C" { */ #define f_macro_fss_nests_t_destroy_simple(nests) \ nests.used = nests.size; \ - while (nests.used > 0) { \ + while (nests.used) { \ nests.used--; \ f_macro_fss_nest_t_destroy_simple(nests.array[nests.used]); \ - if (!nests.used) { \ - if (f_memory_destroy((void **) & nests.array, sizeof(f_fss_nest_t), nests.size)) { \ - nests.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & nests.array, sizeof(f_fss_nest_t), nests.size); \ + nests.size = 0; /** * Resize a fss content nests. diff --git a/level_0/f_fss/c/fss_set.h b/level_0/f_fss/c/fss_set.h index de4eb24..0d2ac75 100644 --- a/level_0/f_fss/c/fss_set.h +++ b/level_0/f_fss/c/fss_set.h @@ -133,7 +133,7 @@ extern "C" { #define f_macro_fss_sets_t_delete(status, sets) \ status = F_none; \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_set_t_delete(status, sets.array[sets.used]); \ if (status != F_none) break; \ @@ -150,7 +150,7 @@ extern "C" { #define f_macro_fss_sets_t_destroy(status, sets) \ status = F_none; \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_set_t_destroy(status, sets.array[sets.used]); \ if (status != F_none) break; \ @@ -165,15 +165,12 @@ extern "C" { */ #define f_macro_fss_sets_t_delete_simple(sets) \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_set_t_delete_simple(sets.array[sets.used]); \ - if (!sets.used) { \ - if (f_memory_delete((void **) & sets.array, sizeof(f_fss_set_t), sets.size)) { \ - sets.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & sets.array, sizeof(f_fss_set_t), sets.size); \ + sets.size = 0; /** * Destroy a fss content sets. @@ -185,12 +182,9 @@ extern "C" { while (sets.used > 0) { \ sets.used--; \ f_macro_fss_set_t_destroy_simple(sets.array[sets.used]); \ - if (!sets.used) { \ - if (f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_t), sets.size)) { \ - sets.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_t), sets.size); \ + sets.size = 0; /** * Resize a fss content sets. @@ -403,7 +397,7 @@ extern "C" { #define f_macro_fss_set_quotes_t_delete(status, sets) \ status = F_none; \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_set_quote_t_delete(status, sets.array[sets.used]); \ if (status != F_none) break; \ @@ -420,7 +414,7 @@ extern "C" { #define f_macro_fss_set_quotes_t_destroy(status, sets) \ status = F_none; \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_set_quote_t_destroy(status, sets.array[sets.used]); \ if (status != F_none) break; \ @@ -435,15 +429,12 @@ extern "C" { */ #define f_macro_fss_set_quotes_t_delete_simple(sets) \ sets.used = sets.size; \ - while (sets.used > 0) { \ + while (sets.used) { \ sets.used--; \ f_macro_fss_set_quote_t_delete_simple(sets.array[sets.used]); \ - if (!sets.used) { \ - if (f_memory_delete((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size)) { \ - sets.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size); \ + sets.size = 0; /** * Destroy a fss content sets. @@ -455,12 +446,9 @@ extern "C" { while (sets.used > 0) { \ sets.used--; \ f_macro_fss_set_quote_t_destroy_simple(sets.array[sets.used]); \ - if (!sets.used) { \ - if (f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size)) { \ - sets.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size); \ + sets.size = 0; /** * Resize a fss content sets. diff --git a/level_0/f_memory/c/memory.c b/level_0/f_memory/c/memory.c index 685f3ad..7552a35 100644 --- a/level_0/f_memory/c/memory.c +++ b/level_0/f_memory/c/memory.c @@ -5,18 +5,19 @@ extern "C" { #endif #ifndef _di_f_memory_new_ - f_return_status f_memory_new(void **pointer, const f_memory_size_t type, const f_memory_length length) { + f_return_status f_memory_new(void **pointer, const f_memory_size_t size, const f_memory_length length) { #ifndef _di_level_0_parameter_checking_ - if (type <= 0) return F_status_set_error(F_parameter); + if (size <= 0) return F_status_set_error(F_parameter); + if (length <= 0) return F_status_set_error(F_parameter); if (!pointer) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ // prevent double-allocations. - if (*pointer != 0) return F_none; + if (*pointer) return F_none; - // Some people use malloc(type * length) to produce the same results. + // Some people use malloc(size * length) to produce the same results. // This has been observed to sometimes causes an increase in L1/L2 cache misses (0.02% L1 increase, 0.01% L2 increase). - *pointer = calloc(type, length); + *pointer = calloc(size, length); if (*pointer) { return F_none; @@ -26,52 +27,52 @@ extern "C" { } #endif // _di_f_memory_new_ -#if ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) ) - f_return_status f_memory_delete(void **pointer, const f_memory_size_t type, const f_memory_length length) { +#if !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_)) + f_return_status f_memory_delete(void **pointer, const f_memory_size_t size, const f_memory_length length) { #ifndef _di_level_0_parameter_checking_ if (!pointer) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ // prevent double-frees. - if (!*pointer) return F_none; + if (!*pointer || !size || !length) return F_none; free(*pointer); // it has been deallocated, so reset the pointer. - if (*pointer != 0) *pointer = 0; + *pointer = 0; return F_none; } -#endif // ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) ) +#endif // !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_)) -#if ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) - f_return_status f_memory_destroy(void **pointer, const f_memory_size_t type, const f_memory_length length) { +#if !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_)) + f_return_status f_memory_destroy(void **pointer, const f_memory_size_t size, const f_memory_length length) { #ifndef _di_level_0_parameter_checking_ if (length < 0) return F_status_set_error(F_parameter); - if (type <= 0) return F_status_set_error(F_parameter); + if (size <= 0) return F_status_set_error(F_parameter); if (!pointer) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ // prevent double-frees. - if (!*pointer) return F_none; + if (!*pointer || !size || !length) return F_none; if (length > 0) { - memset(*pointer, 0, type * length); + memset(*pointer, 0, size * length); } free(*pointer); // it has been deallocated, so reset the pointer. - if (*pointer != 0) *pointer = 0; + *pointer = 0; return F_none; } -#endif // ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) +#endif // !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_)) -#if ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) ) - f_return_status f_memory_resize(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length) { +#if !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_)) + f_return_status f_memory_resize(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length) { #ifndef _di_level_0_parameter_checking_ - if (type <= 0) return F_status_set_error(F_parameter); + if (size <= 0) return F_status_set_error(F_parameter); if (old_length < 0) return F_status_set_error(F_parameter); if (new_length < 0) return F_status_set_error(F_parameter); if (!pointer) return F_status_set_error(F_parameter); @@ -80,18 +81,18 @@ extern "C" { // don't be wasteful. if (old_length == new_length) return F_none; - if (*pointer != 0) { + if (*pointer) { void *new_pointer = 0; // allocate new space if (new_length > 0) { - new_pointer = realloc(*pointer, type * new_length); + new_pointer = realloc(*pointer, size * new_length); } else { free(*pointer); // it has been deallocated, so reset the pointer - if (*pointer != 0) *pointer = 0; + *pointer = 0; return F_none; } @@ -99,9 +100,9 @@ extern "C" { if (new_pointer) { if (new_pointer != *pointer) { if (new_length > old_length) { - // uint8_t * is of a data type size of 1, casting it to uint8_t should result in a single-length increment. + // uint8_t * is of a data size size of 1, casting it to uint8_t should result in a single-length increment. // this is done to avoid problems with (void *) having arithmetic issues. - memset(((uint8_t *) new_pointer) + (type * old_length), 0, type * (new_length - old_length)); + memset(((uint8_t *) new_pointer) + (size * old_length), 0, size * (new_length - old_length)); } *pointer = new_pointer; @@ -111,7 +112,7 @@ extern "C" { } } else if (new_length > 0) { - *pointer = calloc(type, new_length); + *pointer = calloc(size, new_length); if (*pointer) { return F_none; @@ -123,12 +124,12 @@ extern "C" { return F_status_set_error(F_memory_reallocation); } -#endif // ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) ) +#endif // !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_)) -#if ! ( defined (_di_f_memory_adjust_) || defined (_f_memory_FORCE_fast_memory_) ) - f_return_status f_memory_adjust(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length) { +#if !(defined(_di_f_memory_adjust_) || defined(_f_memory_FORCE_fast_memory_)) + f_return_status f_memory_adjust(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length) { #ifndef _di_level_0_parameter_checking_ - if (type <= 0) return F_status_set_error(F_parameter); + if (size <= 0) return F_status_set_error(F_parameter); if (old_length < 0) return F_status_set_error(F_parameter); if (new_length < 0) return F_status_set_error(F_parameter); if (!pointer) return F_status_set_error(F_parameter); @@ -137,26 +138,26 @@ extern "C" { // don't be wasteful if (old_length == new_length) return F_none; - if (*pointer != 0) { + if (*pointer) { void *new_pointer = 0; if (old_length > 0) { if (new_length < old_length) { - // uint8_t * is of a data type size of 1, casting it to uint8_t should result in a single-length increment. + // uint8_t * is of a data size size of 1, casting it to uint8_t should result in a single-length increment. // this is done to avoid problems with (void *) having arithmetic issues. - memset(((uint8_t *) *pointer) + new_length, 0, type * (old_length - new_length)); + memset(((uint8_t *) *pointer) + new_length, 0, size * (old_length - new_length)); } } // allocate new space. if (new_length > 0) { - new_pointer = realloc(*pointer, type * new_length); + new_pointer = realloc(*pointer, size * new_length); } else { free(*pointer); // it has been deallocated, so reset the pointer - if (*pointer != 0) *pointer = 0; + *pointer = 0; return F_none; } @@ -164,9 +165,9 @@ extern "C" { if (new_pointer) { if (new_pointer != *pointer) { if (new_length > old_length) { - // uint8_t * is of a data type size of 1, casting it to bool should result in a single-length increment. + // uint8_t * is of a data size size of 1, casting it to bool should result in a single-length increment. // this is done to avoid problems with (void *) having arithmetic issues. - memset(((uint8_t *) new_pointer) + (type * old_length), 0, type * (new_length - old_length)); + memset(((uint8_t *) new_pointer) + (size * old_length), 0, size * (new_length - old_length)); } *pointer = new_pointer; @@ -176,7 +177,7 @@ extern "C" { } } else if (new_length > 0) { - *pointer = calloc(type, new_length); + *pointer = calloc(size, new_length); if (*pointer) { return F_none; @@ -188,7 +189,7 @@ extern "C" { return F_status_set_error(F_memory_reallocation); } -#endif // ! ( defined (_di_f_memory_adjust_) || defined (_f_memory_FORCE_fast_memory_) ) +#endif // !(defined(_di_f_memory_adjust_) || defined(_f_memory_FORCE_fast_memory_)) #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_memory/c/memory.h b/level_0/f_memory/c/memory.h index 2bdde68..221b9f2 100644 --- a/level_0/f_memory/c/memory.h +++ b/level_0/f_memory/c/memory.h @@ -80,10 +80,12 @@ extern "C" { * * @param pointer * A pointer that will be updated to the address of the newly allocated memory. - * @param type - * The block size, in bytes (type * length = allocated size). + * @param size + * The block size, in bytes (size * length = allocated size). + * Must be greater than 0. * @param length * The total number of blocks to be allocated. + * Must be greater than 0. * * @return * F_none on success. @@ -93,7 +95,7 @@ extern "C" { * @see calloc() */ #ifndef _di_f_memory_new_ - extern f_return_status f_memory_new(void **pointer, const f_memory_size_t type, const f_memory_length length); + extern f_return_status f_memory_new(void **pointer, const f_memory_size_t size, const f_memory_length length); #endif // _di_f_memory_new_ /** @@ -105,10 +107,12 @@ extern "C" { * * @param pointer * A pointer to the address that will be freed. - * @param type - * The block size, in bytes (type * length = allocated size). + * @param size + * The block size, in bytes (size * length = allocated size). + * If size is 0 then no delete is performed. * @param length * The total number of blocks to be allocated. + * If length is 0 then no delete is performed. * * @return * F_none on success. @@ -116,9 +120,9 @@ extern "C" { * * @see free() */ -#if ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) ) - extern f_return_status f_memory_delete(void **pointer, const f_memory_size_t type, const f_memory_length length); -#endif // ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) ) +#if !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_)) + extern f_return_status f_memory_delete(void **pointer, const f_memory_size_t size, const f_memory_length length); +#endif // !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_)) /** * Securely deletes some dynamically allocated data. @@ -127,10 +131,12 @@ extern "C" { * * @param pointer * A pointer to the address that will be freed. - * @param type - * The block size, in bytes (type * length = allocated size). + * @param size + * The block size, in bytes (size * length = allocated size). + * If size is 0 then no delete is performed. * @param length * The total number of blocks to be allocated. + * If length is 0 then no delete is performed. * * @return * F_none on success. @@ -139,9 +145,9 @@ extern "C" { * @see free() * @see memset() */ -#if ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) - extern f_return_status f_memory_destroy(void **pointer, const f_memory_size_t type, const f_memory_length length); -#endif // ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) +#if !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_)) + extern f_return_status f_memory_destroy(void **pointer, const f_memory_size_t size, const f_memory_length length); +#endif // !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_)) /** * Resize dynamically allocated data. @@ -150,8 +156,8 @@ extern "C" { * * @param pointer * A pointer to the address that will be resized. - * @param type - * The block size, in bytes (type * length = allocated size). + * @param size + * The block size, in bytes (size * length = allocated size). * @param old_length * The total number of blocks representing the length to be resized from. * @param new_length @@ -166,9 +172,9 @@ extern "C" { * @see memset() * @see realloc() */ -#if ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) ) - extern f_return_status f_memory_resize(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length); -#endif // ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) ) +#if !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_)) + extern f_return_status f_memory_resize(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length); +#endif // !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_)) /** * Securely resize dynamically allocated data. @@ -177,8 +183,8 @@ extern "C" { * * @param pointer * A pointer to the address that will be resized. - * @param type - * The block size, in bytes (type * length = allocated size). + * @param size + * The block size, in bytes (size * length = allocated size). * @param old_length * The total number of blocks representing the length to be resized from. * @param new_length @@ -193,8 +199,8 @@ extern "C" { * @see memset() * @see realloc() */ -#if ! ( defined (_di_f_memory_adjust_) || defined (_f_memory_FORCE_fast_memory_) ) - extern f_return_status f_memory_adjust(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length); +#if !(defined(_di_f_memory_adjust_) || defined(_f_memory_FORCE_fast_memory_)) + extern f_return_status f_memory_adjust(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length); #endif // _di_f_memory_adjust_ #ifdef __cplusplus diff --git a/level_0/f_memory/c/memory_structure.h b/level_0/f_memory/c/memory_structure.h index 6df81cf..fd4f5db 100644 --- a/level_0/f_memory/c/memory_structure.h +++ b/level_0/f_memory/c/memory_structure.h @@ -90,10 +90,9 @@ extern "C" { */ #ifndef _di_f_macro_memory_structure_delete_simple_ #define f_macro_memory_structure_t_delete_simple(structure, type) \ - if (f_memory_delete((void **) & structure.array, sizeof(type), structure.size) == F_none) { \ - structure.size = 0; \ - structure.used = 0; \ - } + f_memory_delete((void **) & structure.array, sizeof(type), structure.size); \ + structure.size = 0; \ + structure.used = 0; #endif // _di_f_macro_memory_structure_delete_simple_ /** @@ -104,10 +103,9 @@ extern "C" { */ #ifndef _di_f_macro_memory_structure_destroy_simple_ #define f_macro_memory_structure_t_destroy_simple(structure, type) \ - if (f_memory_destroy((void **) & structure.array, sizeof(type), structure.size) == F_none) { \ - structure.size = 0; \ - structure.used = 0; \ - } + f_memory_destroy((void **) & structure.array, sizeof(type), structure.size); \ + structure.size = 0; \ + structure.used = 0; #endif // _di_f_macro_memory_structure_destroy_simple_ /** @@ -190,7 +188,7 @@ extern "C" { #define f_macro_memory_structures_t_delete(status, structures, type_structure, type_structures) \ status = F_none; \ structures.used = structures.size; \ - while (structures.used > 0) { \ + while (structures.used) { \ structures.used--; \ f_macro_memory_structure_t_delete(status, structures.array[structures.used], type_structure); \ if (status != F_none) break; \ @@ -211,7 +209,7 @@ extern "C" { #define f_macro_memory_structures_t_destroy(status, structures, type_structure, type_structures) \ status = F_none; \ structures.used = structures.size; \ - while (structures.used > 0) { \ + while (structures.used) { \ structures.used--; \ f_macro_memory_structure_t_destroy(status, structures.array[structures.used], type_structure); \ if (status != F_none) break; \ @@ -230,15 +228,12 @@ extern "C" { #ifndef _di_f_macro_memory_structures_delete_simple_ #define f_macro_memory_structures_t_delete_simple(structures, type_structure, type_structures) \ structures.used = structures.size; \ - while (structures.used > 0) { \ + while (structures.used) { \ structures.used--; \ f_macro_memory_structure_t_delete_simple(structures.array[structures.used], type_structure); \ } \ - if (!structures.used) { \ - if (f_memory_delete((void **) & structures.array, sizeof(type_structures), structures.size)) { \ - structures.size = 0; \ - } \ - } + f_memory_delete((void **) & structures.array, sizeof(type_structures), structures.size); \ + structures.size = 0; #endif // _di_f_macro_memory_structures_delete_simple_ /** @@ -251,15 +246,12 @@ extern "C" { #ifndef _di_f_macro_memory_structures_destroy_simple_ #define f_macro_memory_structures_t_destroy_simple(structures, type_structure, type_structures) \ structures.used = structures.size; \ - while (structures.used > 0) { \ + while (structures.used) { \ structures.used--; \ f_macro_memory_structure_t_destroy_simple(structures.array[structures.used], type_structure); \ } \ - if (!structures.used) { \ - if (f_memory_destroy((void **) & structures.array, sizeof(type_structures), structures.size)) { \ - structures.size = 0; \ - } \ - } + f_memory_destroy((void **) & structures.array, sizeof(type_structures), structures.size); \ + structures.size = 0; #endif // _di_f_macro_memory_structures_destroy_simple_ /** @@ -344,11 +336,11 @@ extern "C" { #define f_macro_memory_structure_macro_increment(status, structure, step, step_default, macro_resize, error_too_large) \ if (structure.used + step > structure.size) { \ if (structure.used + step_default > f_array_length_t_size) { \ - if (structure.used + step > structure.size > f_array_length_t_size) { \ + if (structure.used + step > f_array_length_t_size) { \ status = F_status_set_error(error_too_large); \ } \ else { \ - macro_resize(status, structure, structure.size + step); \ + macro_resize(status, structure, structure.used + step); \ } \ } \ else { \ diff --git a/level_0/f_string/c/string_dynamic.h b/level_0/f_string/c/string_dynamic.h index ae65574..f950bf2 100644 --- a/level_0/f_string/c/string_dynamic.h +++ b/level_0/f_string/c/string_dynamic.h @@ -159,7 +159,7 @@ extern "C" { #define f_macro_string_dynamics_t_delete(status, dynamics) \ status = F_none; \ dynamics.used = dynamics.size; \ - while (dynamics.used > 0) { \ + while (dynamics.used) { \ dynamics.used--; \ f_macro_string_dynamic_t_delete(status, dynamics.array[dynamics.used]); \ if (status != F_none) break; \ @@ -170,7 +170,7 @@ extern "C" { #define f_macro_string_dynamics_t_destroy(status, dynamics) \ status = F_none; \ dynamics.used = dynamics.size; \ - while (dynamics.used > 0) { \ + while (dynamics.used) { \ dynamics.used--; \ f_macro_string_dynamic_t_destroy(status, dynamics.array[dynamics.used]); \ if (status != F_none) break; \ @@ -180,27 +180,21 @@ extern "C" { #define f_macro_string_dynamics_t_delete_simple(dynamics) \ dynamics.used = dynamics.size; \ - while (dynamics.used > 0) { \ + while (dynamics.used) { \ dynamics.used--; \ f_macro_string_dynamic_t_delete_simple(dynamics.array[dynamics.used]); \ - if (!dynamics.used) { \ - if (f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size)) { \ - dynamics.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size); \ + dynamics.size = 0; #define f_macro_string_dynamics_t_destroy_simple(dynamics) \ dynamics.used = dynamics.size; \ while (dynamics.used > 0) { \ dynamics.used--; \ f_macro_string_dynamic_t_destroy_simple(dynamics.array[dynamics.used]); \ - if (!dynamics.used) { \ - if (f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size)) { \ - dynamics.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size); \ + dynamics.size = 0; #define f_macro_string_dynamics_t_resize(status, dynamics, new_length) \ status = F_none; \ diff --git a/level_0/f_string/c/string_map.h b/level_0/f_string/c/string_map.h index 7b8dd99..b568125 100644 --- a/level_0/f_string/c/string_map.h +++ b/level_0/f_string/c/string_map.h @@ -89,7 +89,7 @@ extern "C" { #define f_macro_string_maps_t_delete(status, maps) \ status = F_none; \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_t_delete(status, maps.array[maps.used]); \ if (status != F_none) break; \ @@ -100,7 +100,7 @@ extern "C" { #define f_macro_string_maps_t_destroy(status, maps) \ status = F_none; \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_t_destroy(status, maps.array[maps.used]); \ if (status != F_none) break; \ @@ -110,27 +110,21 @@ extern "C" { #define f_macro_string_maps_t_delete_simple(maps) \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_t_delete_simple(maps.array[maps.used]); \ - if (!maps.used) { \ - if (f_memory_delete((void **) & maps.array, sizeof(f_string_map_t), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & maps.array, sizeof(f_string_map_t), maps.size); \ + maps.size = 0; #define f_macro_string_maps_t_destroy_simple(maps) \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_t_destroy_simple(maps.array[maps.used]); \ - if (!maps.used) { \ - if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map_t), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & maps.array, sizeof(f_string_map_t), maps.size); \ + maps.size = 0; #define f_macro_string_maps_t_resize(status, maps, new_length) \ status = F_none; \ @@ -240,7 +234,7 @@ extern "C" { #define f_macro_string_map_multis_t_delete(status, maps) \ status = F_none; \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_multi_t_delete(status, maps.array[maps.used]); \ if (status != F_none) break; \ @@ -251,7 +245,7 @@ extern "C" { #define f_macro_string_map_multis_t_destroy(status, maps) \ status = F_none; \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_multi_t_destroy(status, maps.array[maps.used]); \ if (status != F_none) break; \ @@ -261,27 +255,21 @@ extern "C" { #define f_macro_string_map_multis_t_delete_simple(maps) \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_multi_t_delete_simple(maps.array[maps.used]); \ - if (!maps.used) { \ - if (f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size); \ + maps.size = 0; #define f_macro_string_map_multis_t_destroy_simple(maps) \ maps.used = maps.size; \ - while (maps.used > 0) { \ + while (maps.used) { \ maps.used--; \ f_macro_string_map_multi_t_destroy_simple(maps.array[maps.used]); \ - if (!maps.used) { \ - if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } + } \ + f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size); \ + maps.size = 0; #define f_macro_string_map_multis_t_resize(status, maps, new_length) \ status = F_none; \ diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index ea7ab3e..2ca1fd5 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -1008,74 +1008,89 @@ extern "C" { #if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) f_return_status private_fl_fss_delimits_increase(f_fss_delimits_t *delimits) { - f_status_t status = F_none; if (delimits->used + 1 > delimits->size) { - if (delimits->size + f_fss_default_allocation_step > f_string_length_t_size) { - if (delimits->size + 1 > f_string_length_t_size) { - return F_status_set_error(F_string_too_large); + f_array_length_t size = delimits->used + f_fss_default_allocation_step; + + if (size > f_array_length_t_size) { + if (delimits->used + 1 > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); } - f_macro_fss_delimits_t_resize(status, (*delimits), (delimits->size + 1)); - } - else { - f_macro_fss_delimits_t_resize(status, (*delimits), (delimits->size + f_fss_default_allocation_step)); + size = f_string_length_t_size; } + + f_status_t status = F_none; + + f_macro_fss_delimits_t_resize(status, (*delimits), size); + + return status; } - return status; + return F_none; } #endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) #if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) f_return_status private_fl_fss_delimits_increase_by(const f_string_length_t amount, f_fss_delimits_t *delimits) { - f_status_t status = F_none; if (delimits->used + amount > delimits->size) { - if (delimits->size + amount > f_string_length_t_size) { - return F_status_set_error(F_string_too_large); + if (delimits->used + amount > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); } - f_macro_fss_delimits_t_resize(status, (*delimits), (delimits->size + amount)); + f_status_t status = F_none; + + f_macro_fss_delimits_t_resize(status, (*delimits), delimits->used + amount); + + return status; } - return status; + return F_none; } #endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) #if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) f_return_status private_fl_fss_destination_increase(f_string_dynamic_t *destination) { - f_status_t status = F_none; - if (destination->size + f_fss_default_allocation_step > f_string_length_t_size) { - if (destination->size == f_string_length_t_size) { - return F_status_set_error(F_string_too_large); + if (destination->used + 1 > destination->size) { + f_array_length_t size = destination->used + f_fss_default_allocation_step; + + if (size > f_string_length_t_size) { + if (destination->used + 1 > f_string_length_t_size) { + return F_status_set_error(F_string_too_large); + } + + size = f_string_length_t_size; } - f_macro_string_dynamic_t_resize(status, (*destination), f_string_length_t_size); - return F_string_too_large; + f_status_t status = F_none; + + f_macro_string_dynamic_t_resize(status, (*destination), size); + + return status; } - f_macro_string_dynamic_t_resize(status, (*destination), destination->size + f_fss_default_allocation_step); - return status; + return F_none; } #endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) #if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) f_return_status private_fl_fss_destination_increase_by(const f_string_length_t amount, f_string_dynamic_t *destination) { - f_status_t status = F_none; - if (destination->size + amount > f_string_length_t_size) { - if (destination->size == f_string_length_t_size) { + if (destination->used + amount > destination->size) { + if (destination->used + amount > f_string_length_t_size) { return F_status_set_error(F_string_too_large); } - f_macro_string_dynamic_t_resize(status, (*destination), f_string_length_t_size); - return F_string_too_large; + f_status_t status = F_none; + + f_macro_string_dynamic_t_resize(status, (*destination), destination->used + amount); + + return status; } - f_macro_string_dynamic_t_resize(status, (*destination), destination->size + amount); - return status; + return F_none; } #endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) @@ -1099,43 +1114,51 @@ extern "C" { #if !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) f_return_status private_fl_fss_nest_increase(f_fss_nest_t *nest) { - f_status_t status = F_none; if (nest->used + 1 > nest->size) { - if (nest->size + f_fss_default_allocation_step > f_array_length_t_size) { - if (nest->size + 1 > f_array_length_t_size) { + f_array_length_t size = nest->used + f_fss_default_allocation_step; + + if (size > f_string_length_t_size) { + if (nest->used + 1 > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - f_macro_fss_nest_t_resize(status, (*nest), (nest->size + 1)); - } - else { - f_macro_fss_nest_t_resize(status, (*nest), (nest->size + f_fss_default_allocation_step)); + size = f_array_length_t_size; } + + f_status_t status = F_none; + + f_macro_fss_nest_t_resize(status, (*nest), size); + + return status; } - return status; + return F_none; } #endif // !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) #if !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_basic_content_read_) || !defined(_di_fl_fss_extended_object_read_) || !defined(_di_fl_fss_extended_content_read_) || !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_basic_list_content_read_) || !defined(_di_fl_fss_extended_list_object_read_) || !defined(_di_fl_fss_extended_list_content_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) f_return_status private_fl_fss_ranges_increase(f_string_ranges_t *ranges) { - f_status_t status = F_none; if (ranges->used + 1 > ranges->size) { - if (ranges->size + f_fss_default_allocation_step > f_array_length_t_size) { - if (ranges->size + 1 > f_array_length_t_size) { + f_array_length_t size = ranges->used + f_fss_default_allocation_step; + + if (size > f_string_length_t_size) { + if (ranges->used + 1 > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - f_macro_string_ranges_t_resize(status, (*ranges), (ranges->size + 1)); - } - else { - f_macro_string_ranges_t_resize(status, (*ranges), (ranges->size + f_fss_default_allocation_step)); + size = f_array_length_t_size; } + + f_status_t status = F_none; + + f_macro_string_ranges_t_resize(status, (*ranges), size); + + return status; } - return status; + return F_none; } #endif // !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_basic_content_read_) || !defined(_di_fl_fss_extended_object_read_) || !defined(_di_fl_fss_extended_content_read_) || !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_basic_list_content_read_) || !defined(_di_fl_fss_extended_list_object_read_) || !defined(_di_fl_fss_extended_list_content_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_) diff --git a/level_1/fl_fss/c/private-fss.h b/level_1/fl_fss/c/private-fss.h index 2168987..797aec1 100644 --- a/level_1/fl_fss/c/private-fss.h +++ b/level_1/fl_fss/c/private-fss.h @@ -196,7 +196,7 @@ extern "C" { * @return * F_none on success. * F_memory_reallocation (with error bit) on reallocation error. - * F_array_too_large (with error bit) if appended string length is too large to store in the delimits. + * F_array_too_large (with error bit) if new length is larger than max array length. * * @see fl_fss_basic_content_write_string() * @see fl_fss_basic_object_write_string() @@ -224,7 +224,7 @@ extern "C" { * @return * F_none on success. * F_memory_reallocation (with error bit) on reallocation error. - * F_array_too_large (with error bit) if increased string length is too large to store in the delimits. + * F_array_too_large (with error bit) if new length is larger than max array length. * * @see fl_fss_basic_content_write_string() * @see fl_fss_basic_object_write_string() @@ -249,10 +249,9 @@ extern "C" { * * @return * F_none on success. - * F_string_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. - * F_string_too_large (with error bit) if the new array length is too large. + * F_string_too_large (with error bit) if new length is larger than max string length. * * @see fl_fss_basic_content_write_string() * @see fl_fss_basic_object_write_string() @@ -279,10 +278,9 @@ extern "C" { * * @return * F_none on success. - * F_string_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. - * F_string_too_large (with error bit) if the new array length is too large. + * F_string_too_large (with error bit) if new length is larger than max string length. * * @see fl_fss_basic_content_write_string() * @see fl_fss_basic_object_write_string() @@ -329,7 +327,7 @@ extern "C" { * @return * F_none on success. * F_memory_reallocation (with error bit) on reallocation error. - * F_array_too_large (with error bit) if increased array length is too large to store in the range. + * F_array_too_large (with error bit) if new length is larger than max array length. * * @see fl_fss_embedded_list_object_read() * @see fl_fss_embedded_list_content_read() @@ -347,7 +345,7 @@ extern "C" { * @return * F_none on success. * F_memory_reallocation (with error bit) on reallocation error. - * F_array_too_large (with error bit) if increased array length is too large to store in the range. + * F_array_too_large (with error bit) if new length is larger than max array length. * * @see fl_fss_basic_object_read() * @see fl_fss_basic_content_read() diff --git a/level_1/fl_string/c/private-string.c b/level_1/fl_string/c/private-string.c index 3e68e22..deb0313 100644 --- a/level_1/fl_string/c/private-string.c +++ b/level_1/fl_string/c/private-string.c @@ -530,19 +530,20 @@ extern "C" { #if !defined(_di_fl_string_dynamic_increase_by_) || !defined(_di_fl_string_append_) || !defined(_di_fl_string_dynamic_append_) || !defined(_di_fl_string_append_mash_) || !defined(_di_fl_string_dynamic_mash_) || !defined(_di_fl_string_append_nulless_) || !defined(_di_fl_string_dynamic_append_nulless_) || !defined(_di_fl_string_mash_nulless_) || !defined(_di_fl_string_dynamic_mash_nulless_) || !defined(_di_fl_string_prepend_) || !defined(_di_fl_string_dynamic_prepend_) || !defined(_di_fl_string_prepend_nulless_) || !defined(_di_fl_string_dynamic_prepend_nulless_) f_return_status private_fl_string_dynamic_increase_by(const f_string_length_t amount, f_string_dynamic_t *string) { - f_status_t status = F_none; - if (string->size + amount > f_string_length_t_size) { - if (string->size == f_string_length_t_size) { + if (string->used + amount > string->size) { + if (string->used + amount > f_string_length_t_size) { return F_status_set_error(F_string_too_large); } - f_macro_string_dynamic_t_resize(status, (*string), f_string_length_t_size); - return F_string_too_large; + f_status_t status = F_none; + + f_macro_string_dynamic_t_resize(status, (*string), string->used + amount); + + return status; } - f_macro_string_dynamic_t_resize(status, (*string), string->size + amount); - return status; + return F_none; } #endif // !defined(_di_fl_string_dynamic_increase_by_) || !defined(_di_fl_string_append_) || !defined(_di_fl_string_dynamic_append_) || !defined(_di_fl_string_append_mash_) || !defined(_di_fl_string_dynamic_mash_) || !defined(_di_fl_string_append_nulless_) || !defined(_di_fl_string_dynamic_append_nulless_) || !defined(_di_fl_string_mash_nulless_) || !defined(_di_fl_string_dynamic_mash_nulless_) || !defined(_di_fl_string_prepend_) || !defined(_di_fl_string_dynamic_prepend_) || !defined(_di_fl_string_prepend_nulless_) || !defined(_di_fl_string_dynamic_prepend_nulless_) diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index 591fee4..818e925 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -937,26 +937,31 @@ extern "C" { if (!string) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; + if (string->used + 1 > string->size) { + f_array_length_t size = string->used + f_memory_default_allocation_step; + + if (size > f_string_length_t_size) { + if (string->used + 1 > f_string_length_t_size) { + return F_status_set_error(F_string_too_large); + } - if (string->size + f_memory_default_allocation_step > f_string_length_t_size) { - if (string->size == f_string_length_t_size) { - return F_status_set_error(F_string_too_large); + size = f_string_length_t_size; } - f_macro_string_dynamic_t_resize(status, (*string), f_string_length_t_size); - return F_string_too_large; + f_status_t status = F_none; + + f_macro_string_dynamic_t_resize(status, (*string), size); + + return status; } - f_macro_string_dynamic_t_resize(status, (*string), string->size + f_memory_default_allocation_step); - return status; + return F_none; } #endif // _di_fl_string_dynamic_increase_ #ifndef _di_fl_string_dynamic_increase_by_ f_return_status fl_string_dynamic_increase_by(const f_string_length_t amount, f_string_dynamic_t *string) { #ifndef _di_level_1_parameter_checking_ - if (!amount) return F_status_set_error(F_parameter); if (!string) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -1332,42 +1337,47 @@ extern "C" { if (!strings) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; + if (strings->used + 1 > strings->size) { + f_array_length_t size = strings->used + f_memory_default_allocation_step; - if (strings->size + f_memory_default_allocation_step > f_array_length_t_size) { - if (strings->size == f_array_length_t_size) { - return F_status_set_error(F_array_too_large); + if (size > f_array_length_t_size) { + if (strings->used + 1 > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + size = f_array_length_t_size; } - f_macro_string_dynamics_t_resize(status, (*strings), f_array_length_t_size); - return F_array_too_large; + f_status_t status = F_none; + + f_macro_string_dynamics_t_resize(status, (*strings), size); + + return status; } - f_macro_string_dynamics_t_resize(status, (*strings), strings->size + f_memory_default_allocation_step); - return status; + return F_none; } #endif // _di_fl_string_dynamics_increase_ #ifndef _di_fl_string_dynamics_increase_by_ f_return_status fl_string_dynamics_increase_by(const f_array_length_t amount, f_string_dynamics_t *strings) { #ifndef _di_level_1_parameter_checking_ - if (!amount) return F_status_set_error(F_parameter); if (!strings) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; - - if (strings->size + amount > f_array_length_t_size) { - if (strings->size == f_array_length_t_size) { + if (strings->used + amount > strings->size) { + if (strings->used + amount > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - f_macro_string_dynamics_t_resize(status, (*strings), f_array_length_t_size); - return F_array_too_large; + f_status_t status = F_none; + + f_macro_string_dynamics_t_resize(status, (*strings), strings->used + amount); + + return status; } - f_macro_string_dynamics_t_resize(status, (*strings), strings->size + amount); - return status; + return F_none; } #endif // _di_fl_string_dynamics_increase_by_ @@ -1416,19 +1426,25 @@ extern "C" { if (!lengths) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; + if (lengths->used + 1 > lengths->size) { + f_array_length_t size = lengths->used + f_memory_default_allocation_step; - if (lengths->size + f_memory_default_allocation_step > f_array_length_t_size) { - if (lengths->size == f_array_length_t_size) { - return F_status_set_error(F_array_too_large); + if (size > f_array_length_t_size) { + if (lengths->used + 1 > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + size = f_array_length_t_size; } - f_macro_string_lengths_t_resize(status, (*lengths), f_array_length_t_size); - return F_array_too_large; + f_status_t status = F_none; + + f_macro_string_lengths_t_resize(status, (*lengths), size); + + return status; } - f_macro_string_lengths_t_resize(status, (*lengths), lengths->size + f_memory_default_allocation_step); - return status; + return F_none; } #endif // _di_fl_string_lengths_increase_ @@ -1478,19 +1494,19 @@ extern "C" { if (!lengths) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; - - if (lengths->size + amount > f_array_length_t_size) { - if (lengths->size == f_array_length_t_size) { + if (lengths->used + amount > lengths->size) { + if (lengths->used + amount > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - f_macro_string_lengths_t_resize(status, (*lengths), f_array_length_t_size); - return F_array_too_large; + f_status_t status = F_none; + + f_macro_string_lengths_t_resize(status, (*lengths), lengths->used + amount); + + return status; } - f_macro_string_lengths_t_resize(status, (*lengths), lengths->size + amount); - return status; + return F_none; } #endif // _di_fl_string_lengths_increase_by_ @@ -1500,19 +1516,25 @@ extern "C" { if (!maps) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; + if (maps->used + 1 > maps->size) { + f_array_length_t size = maps->used + f_memory_default_allocation_step; - if (maps->size + f_memory_default_allocation_step > f_array_length_t_size) { - if (maps->size == f_array_length_t_size) { - return F_status_set_error(F_array_too_large); + if (size > f_array_length_t_size) { + if (maps->used + 1 > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + size = f_array_length_t_size; } - f_macro_string_maps_t_resize(status, (*maps), f_array_length_t_size); - return F_array_too_large; + f_status_t status = F_none; + + f_macro_string_maps_t_resize(status, (*maps), size); + + return status; } - f_macro_string_maps_t_resize(status, (*maps), maps->size + f_memory_default_allocation_step); - return status; + return F_none; } #endif // _di_fl_string_maps_increase_ @@ -1523,19 +1545,19 @@ extern "C" { if (!maps) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; - - if (maps->size + amount > f_array_length_t_size) { - if (maps->size == f_array_length_t_size) { + if (maps->used + amount > maps->size) { + if (maps->used + amount > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - f_macro_string_maps_t_resize(status, (*maps), f_array_length_t_size); - return F_array_too_large; + f_status_t status = F_none; + + f_macro_string_maps_t_resize(status, (*maps), maps->used + amount); + + return status; } - f_macro_string_maps_t_resize(status, (*maps), maps->size + amount); - return status; + return F_none; } #endif // _di_fl_string_maps_increase_by_ diff --git a/level_1/fl_string/c/string.h b/level_1/fl_string/c/string.h index c94b84a..3948f13 100644 --- a/level_1/fl_string/c/string.h +++ b/level_1/fl_string/c/string.h @@ -1563,7 +1563,6 @@ extern "C" { * * @return * F_none on success. - * F_string_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. @@ -1587,7 +1586,6 @@ extern "C" { * * @return * F_none on success. - * F_string_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. @@ -1879,7 +1877,6 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. @@ -1903,7 +1900,6 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. @@ -1965,7 +1961,6 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. @@ -1989,7 +1984,6 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. @@ -2051,7 +2045,6 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. @@ -2075,7 +2068,6 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but the requested length is too large for the buffer. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. diff --git a/level_3/controller/c/private-controller.h b/level_3/controller/c/private-controller.h index 7a57e18..18fffbd 100644 --- a/level_3/controller/c/private-controller.h +++ b/level_3/controller/c/private-controller.h @@ -149,15 +149,12 @@ extern "C" { #define macro_controller_rule_actions_t_delete_simple(actions) \ actions.used = actions.size; \ - while (actions.used > 0) { \ + while (actions.used) { \ actions.used--; \ macro_controller_rule_action_t_delete_simple(actions.array[actions.used]); \ - if (!actions.used) { \ - if (f_memory_delete((void **) & actions.array, sizeof(controller_rule_action_t), actions.size)) { \ - actions.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & actions.array, sizeof(controller_rule_action_t), actions.size); \ + actions.size = 0; #endif // _di_controller_rule_actions_t_ #ifndef _di_controller_rule_item_t_ @@ -203,15 +200,12 @@ extern "C" { #define macro_controller_rule_items_t_delete_simple(items) \ items.used = items.size; \ - while (items.used > 0) { \ + while (items.used) { \ items.used--; \ macro_controller_rule_item_t_delete_simple(items.array[items.used]); \ - if (!items.used) { \ - if (f_memory_delete((void **) & items.array, sizeof(controller_rule_item_t), items.size)) { \ - items.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & items.array, sizeof(controller_rule_item_t), items.size); \ + items.size = 0; #endif // _di_controller_rule_items_t_ #ifndef _di_controller_rule_t_ @@ -293,15 +287,12 @@ extern "C" { #define macro_controller_rules_t_delete_simple(rules) \ rules.used = rules.size; \ - while (rules.used > 0) { \ + while (rules.used) { \ rules.used--; \ macro_controller_rule_t_delete_simple(rules.array[rules.used]); \ - if (!rules.used) { \ - if (f_memory_delete((void **) & rules.array, sizeof(controller_rule_t), rules.size)) { \ - rules.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & rules.array, sizeof(controller_rule_t), rules.size); \ + rules.size = 0; #endif // _di_controller_rules_t_ #ifndef _di_controller_entry_action_t_ @@ -365,15 +356,12 @@ extern "C" { #define macro_controller_entry_actions_t_delete_simple(actions) \ actions.used = actions.size; \ - while (actions.used > 0) { \ + while (actions.used) { \ actions.used--; \ macro_controller_entry_action_t_delete_simple(actions.array[actions.used]); \ - if (!actions.used) { \ - if (f_memory_delete((void **) & actions.array, sizeof(controller_entry_action_t), actions.size)) { \ - actions.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & actions.array, sizeof(controller_entry_action_t), actions.size); \ + actions.size = 0; #endif // _di_controller_entry_actions_t_ #ifndef _di_controller_entry_item_t_ @@ -413,15 +401,12 @@ extern "C" { #define macro_controller_entry_items_t_delete_simple(items) \ items.used = items.size; \ - while (items.used > 0) { \ + while (items.used) { \ items.used--; \ macro_controller_entry_item_t_delete_simple(items.array[items.used]); \ - if (!items.used) { \ - if (f_memory_delete((void **) & items.array, sizeof(controller_entry_item_t), items.size)) { \ - items.size = 0; \ - } \ - } \ - } + } \ + f_memory_delete((void **) & items.array, sizeof(controller_entry_item_t), items.size); \ + items.size = 0; #endif // _di_controller_entry_items_t_ #ifndef _di_controller_entry_t_ diff --git a/level_3/controller/c/private-entry.c b/level_3/controller/c/private-entry.c index 28a5f58..49a40ba 100644 --- a/level_3/controller/c/private-entry.c +++ b/level_3/controller/c/private-entry.c @@ -7,23 +7,22 @@ extern "C" { #ifndef _di_controller_entry_actions_increase_by_ f_return_status controller_entry_actions_increase_by(const f_array_length_t amount, controller_entry_actions_t *actions) { - f_status_t status = F_none; - f_string_length_t size = actions->size + amount; - if (size > f_array_length_t_size) { - if (actions->size == f_array_length_t_size) { + if (actions->used + amount > actions->size) { + if (actions->used + amount > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - size = actions->size; - status = F_array_too_large; - } + const f_status_t status = f_memory_resize((void **) & actions->array, sizeof(controller_entry_action_t), actions->size, actions->used + amount); - const f_status_t status_resize = f_memory_resize((void **) & actions->array, sizeof(controller_entry_action_t), actions->size, size); - if (F_status_is_error(status_resize)) return status_resize; + if (F_status_is_error_not(status)) { + actions->size = actions->used + amount; + } - actions->size = size; - return status; + return status; + } + + return F_none; } #endif // _di_controller_entry_actions_increase_by_ @@ -33,8 +32,21 @@ extern "C" { f_status_t status_action = F_none; actions->used = 0; - cache->object_actions.used = 0; - cache->content_actions.used = 0; + + cache->object_actions.used = cache->object_actions.size; + + while (cache->object_actions.used) { + cache->object_actions.used--; + cache->object_actions.array[cache->object_actions.used].start = 1; + cache->object_actions.array[cache->object_actions.used].stop = 0; + } // while + + cache->content_actions.used = cache->content_actions.size; + + while (cache->content_actions.used) { + cache->content_actions.used--; + cache->content_actions.array[cache->content_actions.used].used = 0; + } // while { f_string_range_t range = content_range; @@ -477,23 +489,22 @@ extern "C" { #ifndef _di_controller_entry_items_increase_by_ f_return_status controller_entry_items_increase_by(const f_array_length_t amount, controller_entry_items_t *items) { - f_status_t status = F_none; - f_string_length_t size = items->size + amount; - if (size > f_array_length_t_size) { - if (items->size == f_array_length_t_size) { + if (items->used + amount > items->size) { + if (items->used + amount > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - size = items->size; - status = F_array_too_large; - } + const f_status_t status = f_memory_resize((void **) & items->array, sizeof(controller_entry_item_t), items->size, items->used + amount); - const f_status_t status_resize = f_memory_resize((void **) & items->array, sizeof(controller_entry_items_t), items->size, size); - if (F_status_is_error(status_resize)) return status_resize; + if (F_status_is_error_not(status)) { + items->size = items->used + amount; + } - items->size = size; - return status; + return status; + } + + return F_none; } #endif // _di_controller_entry_items_increase_by_ @@ -553,7 +564,7 @@ extern "C" { } } - if (F_status_is_error_not(status) && cache->object_actions.used) { + if (F_status_is_error_not(status) && cache->object_items.used) { status = controller_entry_items_increase_by(cache->object_items.used, &entry->items); if (F_status_is_error(status)) { @@ -563,9 +574,9 @@ extern "C" { // 0x1 = main found, 0x2 = found existing. uint8_t code = 0; - controller_entry_item_t *item = 0; f_string_range_t *range = 0; + f_array_length_t at = 0; f_array_length_t i = 0; f_array_length_t j = 0; @@ -575,6 +586,7 @@ extern "C" { code -= 0x2; } + at = 0; range = 0; cache->line_action = 0; @@ -588,7 +600,6 @@ extern "C" { cache->object_actions.used = 0; - cache->buffer_file.used = 0; cache->buffer_path.used = 0; cache->name_action.used = 0; @@ -608,10 +619,10 @@ extern "C" { break; } - status = fl_string_dynamic_terminate(&cache->name_item); + status = fl_string_dynamic_terminate_after(&cache->name_item); if (F_status_is_error(status)) { - fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true); + fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true); break; } @@ -646,40 +657,40 @@ extern "C" { if (fl_string_dynamic_compare_string(controller_string_main, cache->name_item, controller_string_main_length) == F_equal_to) { code |= 0x1; - item = &entry->items.array[0]; + at = 0; if (!entry->items.used) { entry->items.used = 1; } } else if (entry->items.used) { - item = &entry->items.array[entry->items.used++]; + at = entry->items.used++; } else { // skip position 0, which is reserved for "main". - item = &entry->items.array[1]; + at = 1; entry->items.used = 2; } - item->line = cache->line_item; + entry->items.array[at].line = cache->line_item; - status = fl_string_dynamic_append(cache->name_item, &item->name); + status = fl_string_dynamic_append(cache->name_item, &entry->items.array[at].name); if (F_status_is_error(status)) { fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_append", F_true); break; } - status = fl_string_dynamic_terminate(&item->name); + status = fl_string_dynamic_terminate_after(&entry->items.array[at].name); if (F_status_is_error(status)) { - fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true); + fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true); break; } - status = controller_entry_actions_read(data, setting, *range, cache, &item->actions); + status = controller_entry_actions_read(data, setting, *range, cache, &entry->items.array[at].actions); if (F_status_is_error(status)) { controller_entry_error_print(data.error, *cache); @@ -749,10 +760,10 @@ extern "C" { break; } - status = fl_string_dynamic_terminate(&cache->name_item); + status = fl_string_dynamic_terminate_after(&cache->name_item); if (F_status_is_error(status)) { - fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true); + fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true); break; } @@ -763,10 +774,10 @@ extern "C" { break; } - status = fl_string_dynamic_terminate(&cache->name_item); + status = fl_string_dynamic_terminate_after(&cache->name_item); if (F_status_is_error(status)) { - fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true); + fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true); break; } diff --git a/level_3/controller/c/private-entry.h b/level_3/controller/c/private-entry.h index 4303094..b0c656b 100644 --- a/level_3/controller/c/private-entry.h +++ b/level_3/controller/c/private-entry.h @@ -81,7 +81,7 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but requested size is too small (resize is smaller than requested length). + * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length. * * Errors (with error bit) from: f_memory_resize(). * @@ -159,7 +159,7 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but requested size is too small (resize is smaller than requested length). + * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length. * * Errors (with error bit) from: f_memory_resize(). * diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index 1e0a4aa..127a1af 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -53,23 +53,22 @@ extern "C" { #ifndef _di_controller_rule_actions_increase_by_ f_return_status controller_rule_actions_increase_by(const f_array_length_t amount, controller_rule_actions_t *actions) { - f_status_t status = F_none; - f_string_length_t size = actions->size + amount; - if (size > f_array_length_t_size) { - if (actions->size == f_array_length_t_size) { + if (actions->used + amount > actions->size) { + if (actions->used + amount > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - size = actions->size; - status = F_array_too_large; - } + const f_status_t status = f_memory_resize((void **) & actions->array, sizeof(controller_rule_action_t), actions->size, actions->used + amount); - const f_status_t status_resize = f_memory_resize((void **) & actions->array, sizeof(controller_rule_action_t), actions->size, size); - if (F_status_is_error(status_resize)) return status_resize; + if (F_status_is_error_not(status)) { + actions->size = actions->used + amount; + } - actions->size = size; - return status; + return status; + } + + return F_none; } #endif // _di_controller_rule_actions_increase_by_ @@ -418,23 +417,22 @@ extern "C" { #ifndef _di_controller_rule_items_increase_by_ f_return_status controller_rule_items_increase_by(const f_array_length_t amount, controller_rule_items_t *items) { - f_status_t status = F_none; - f_string_length_t size = items->size + amount; - if (size > f_array_length_t_size) { - if (items->size == f_array_length_t_size) { + if (items->used + amount > items->size) { + if (items->used + amount > f_array_length_t_size) { return F_status_set_error(F_array_too_large); } - size = items->size; - status = F_array_too_large; - } + const f_status_t status = f_memory_resize((void **) & items->array, sizeof(controller_rule_item_t), items->size, items->used + amount); - const f_status_t status_resize = f_memory_resize((void **) & items->array, sizeof(controller_rule_item_t), items->size, size); - if (F_status_is_error(status_resize)) return status_resize; + if (F_status_is_error_not(status)) { + items->size = items->used + amount; + } - items->size = size; - return status; + return status; + } + + return F_none; } #endif // _di_controller_rule_items_increase_by_ diff --git a/level_3/controller/c/private-rule.h b/level_3/controller/c/private-rule.h index e906831..c8cb665 100644 --- a/level_3/controller/c/private-rule.h +++ b/level_3/controller/c/private-rule.h @@ -119,7 +119,7 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but requested size is too small (resize is smaller than requested length). + * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length. * * Errors (with error bit) from: f_memory_resize(). */ @@ -220,7 +220,7 @@ extern "C" { * * @return * F_none on success. - * F_array_too_large on success, but requested size is too small (resize is smaller than requested length). + * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length. * * Errors (with error bit) from: f_memory_resize(). *