]> Kevux Git Server - fll/commitdiff
Update: make fl_fss _increase() and _increase_by() functions similar to the fl_string...
authorKevin Day <thekevinday@gmail.com>
Wed, 11 Nov 2020 05:53:59 +0000 (23:53 -0600)
committerKevin Day <thekevinday@gmail.com>
Wed, 11 Nov 2020 05:53:59 +0000 (23:53 -0600)
level_1/fl_fss/c/private-fss.c
level_1/fl_fss/c/private-fss.h

index e9e9ddecfcdb6737f2ea6ecc89fcb0f8b7b4743b..2e37d4907c66196f1426c04d19953a03c74a7ea7 100644 (file)
@@ -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_)
index 0a9baed7268419eb9efc602907e34b66dba9dcf9..4a05d562a9ae0e10a4b0fe0c121898a9160bdc69 100644 (file)
@@ -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()