From: Kevin Day Date: Wed, 11 Nov 2020 05:53:59 +0000 (-0600) Subject: Update: make fl_fss _increase() and _increase_by() functions similar to the fl_string... X-Git-Tag: 0.5.2~80 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=1e9a7b2cba8202a88fddfc553ad641c205d464cc;p=fll Update: make fl_fss _increase() and _increase_by() functions similar to the fl_string equivalents. --- diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index e9e9dde..2e37d49 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -1047,19 +1047,16 @@ extern "C" { f_return_status private_fl_fss_destination_increase(f_string_dynamic_t *destination) { f_status_t status = F_none; - if (destination->used + 1 > destination->size) { - if (destination->size + f_fss_default_allocation_step > f_string_length_t_size) { - if (destination->size + 1 > f_string_length_t_size) { - return F_status_set_error(F_string_too_large); - } - - f_macro_string_dynamic_t_resize(status, (*destination), (destination->size + 1)); - } - else { - f_macro_string_dynamic_t_resize(status, (*destination), (destination->size + f_fss_default_allocation_step)); + 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); } + + f_macro_string_dynamic_t_resize(status, (*destination), f_string_length_t_size); + return F_string_too_large; } + f_macro_string_dynamic_t_resize(status, (*destination), destination->size + f_fss_default_allocation_step); return status; } #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_) @@ -1068,14 +1065,16 @@ extern "C" { 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->used + amount > destination->size) { - if (destination->size + amount > f_string_length_t_size) { + if (destination->size + amount > f_string_length_t_size) { + if (destination->size == f_string_length_t_size) { return F_status_set_error(F_string_too_large); } - f_macro_string_dynamic_t_resize(status, (*destination), destination->size + amount); + f_macro_string_dynamic_t_resize(status, (*destination), f_string_length_t_size); + return F_string_too_large; } + f_macro_string_dynamic_t_resize(status, (*destination), destination->size + amount); return status; } #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_) diff --git a/level_1/fl_fss/c/private-fss.h b/level_1/fl_fss/c/private-fss.h index 0a9baed..4a05d56 100644 --- a/level_1/fl_fss/c/private-fss.h +++ b/level_1/fl_fss/c/private-fss.h @@ -245,8 +245,10 @@ extern "C" { * * @return * F_none on success. - * F_memory_reallocation (with error bit) on reallocation error. - * F_string_too_large (with error bit) if appended string length is too large to store in the destination. + * 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. * * @see fl_fss_basic_object_write_string() * @see fl_fss_basic_content_write_string() @@ -271,8 +273,10 @@ extern "C" { * * @return * F_none on success. - * F_memory_reallocation (with error bit) on reallocation error. - * F_string_too_large (with error bit) if increased string length is too large to store in the destination. + * 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. * * @see fl_fss_basic_object_write_string() * @see fl_fss_basic_content_write_string()