]> Kevux Git Server - fll/commitdiff
Bugfix: Invalid content count in FSS Basic List.
authorKevin Day <thekevinday@gmail.com>
Sat, 26 Mar 2022 02:34:34 +0000 (21:34 -0500)
committerKevin Day <thekevinday@gmail.com>
Sat, 26 Mar 2022 02:34:34 +0000 (21:34 -0500)
When F_none_eos or F_none_stop is returned, the content ends up having an additional size than the actual size.
This is happening because found->used++ is incremented immediately before returning.
When either F_none_eos or F_none_stop is returned, the content is not to be incremented.
Only the caller should know when to assume this is a proper ending representing the content end.

The macro private_macro_fl_fss_content_return_on_overflow_delimited() is only used in one place so remove it.

Make sure to initialize the content for all content read functions to ensure the content count is consistent.

level_1/fl_fss/c/fss/basic_list.c
level_1/fl_fss/c/fss/macro.h
level_2/fll_fss/c/fss/basic.c
level_2/fll_fss/c/fss/basic_list.c
level_2/fll_fss/c/fss/embedded_list.c
level_2/fll_fss/c/fss/extended.c
level_2/fll_fss/c/fss/extended_list.c
level_2/fll_fss/c/fss/payload.c

index 8441157a53bcca03c2957635055ef6ff3ccbd561..770d7842c417f6084e5a50bf9202bd40bbbccd6d 100644 (file)
@@ -65,7 +65,7 @@ extern "C" {
 
     bool graph_first = F_true;
 
-    // identify where the object ends.
+    // Identify where the object ends.
     while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) {
 
       if (state.interrupt) {
@@ -538,9 +538,19 @@ extern "C" {
       return status;
     }
 
-    found->array[found->used++].stop = range->start - 1;
+    if (range->start >= buffer.used) {
+      found->array[found->used].stop = buffer.used - 1;
+
+      return F_none_eos;
+    }
+
+    if (range->start > range->stop) {
+      found->array[found->used].stop = range->stop;
 
-    private_macro_fl_fss_content_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
+      return F_none_stop;
+    }
+
+    found->array[found->used++].stop = range->start - 1;
 
     return F_fss_found_content;
   }
index c489f94d21a3d6a06379041080575d72fb577c1c..ab1835e2e750749ccaccf4c496962a8f3dff0671 100644 (file)
@@ -56,18 +56,6 @@ extern "C" {
     }
 #endif // _di_macro_fl_fss_content_with_comments_return_on_overflow_
 
-#ifndef _di_macro_fl_fss_content_return_on_overflow_delimited_
-  #define private_macro_fl_fss_content_return_on_overflow_delimited(buffer, range, found, eos_status, stop_status) \
-    if (range.start >= buffer.used) { \
-      found.array[found.used].stop = buffer.used - 1; \
-      return eos_status; \
-    } \
-    else if (range.start > range.stop) { \
-      found.array[found.used].stop = range.stop; \
-      return stop_status; \
-    }
-#endif // _di_macro_fl_fss_content_return_on_overflow_delimited_
-
 #ifndef _di_macro_fl_fss_nest_return_on_overflow_
   #define private_macro_fl_fss_nest_return_on_overflow(buffer, range, found, delimits, delimits_used, comments, comments_used, positions, objects, slashes, eos_status, stop_status) \
     if (range.start >= buffer.used) { \
index 51e5fb50a05df579b3a7293791ad4fbd4a3d89db..c1b6cc7486200f1da94216b2fc28e2d3cd63c04e 100644 (file)
@@ -76,6 +76,8 @@ extern "C" {
         if (status == F_fss_found_object) {
           found_data = F_true;
 
+          contents->array[contents->used].used = 0;
+
           status = fl_fss_basic_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits);
           if (F_status_is_error(status)) return status;
 
index f19a4dde41c86940b9f34e3ea4d7c0f35150ba68..85aa98372fcadf76d5f598b2465605b6940ff926 100644 (file)
@@ -60,6 +60,8 @@ extern "C" {
         if (status == F_fss_found_object) {
           found_data = F_true;
 
+          contents->array[contents->used].used = 0;
+
           status = fl_fss_basic_list_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments);
           if (F_status_is_error(status)) return status;
 
index 006b1d1824477d020894e9f2196a42913a7f23c1..6cd0d278e8c7d734ba5dfb4192b8d95323ba5419 100644 (file)
@@ -65,7 +65,8 @@ extern "C" {
 
           break;
         }
-        else if (status == F_fss_found_object_content_not) {
+
+        if (status == F_fss_found_object_content_not) {
           found_data = F_true;
 
           break;
index 98ad6bd735b4d37fcabeeb5f04b01f7fbf4a9c11..93ff506f0855d67033b94184ba571f1033a5c6ad 100644 (file)
@@ -88,6 +88,8 @@ extern "C" {
         if (status == F_fss_found_object) {
           found_data = F_true;
 
+          contents->array[contents->used].used = 0;
+
           if (contents_quoted) {
             status2 = f_uint8s_increase(state.step_small, &contents_quoted->array[contents_quoted->used]);
             if (F_status_is_error(status2)) return status2;
@@ -102,6 +104,7 @@ extern "C" {
         }
         else if (status == F_fss_found_object_content_not) {
           found_data = F_true;
+
           break;
         }
 
@@ -109,7 +112,6 @@ extern "C" {
 
       if (status == F_none_eos || status == F_none_stop) {
         contents->array[contents->used].used++;
-
         ++objects->used;
         ++contents->used;
 
index 4c7e85b61c2b481c3d79ac09023d73f5048a61f1..733085046fcda228717afcf05e01007893a65c5f 100644 (file)
@@ -61,6 +61,8 @@ extern "C" {
         if (status == F_fss_found_object) {
           found_data = F_true;
 
+          contents->array[contents->used].used = 0;
+
           status = fl_fss_extended_list_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments);
           if (F_status_is_error(status)) return status;
 
index 35a14006d0cfdf2edd5acb17cab2d857fd1750e7..d333a50b8a7ccfaa3ae5312e36c5819bf6c99915 100644 (file)
@@ -70,6 +70,8 @@ extern "C" {
         if (status == F_fss_found_object) {
           found_data = F_true;
 
+          contents->array[contents->used].used = 0;
+
           if (fl_string_dynamic_partial_compare_string(f_fss_string_payload_s.string, buffer, f_fss_string_payload_s.used, objects->array[objects->used]) == F_equal_to) {
             status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]);
             if (F_status_is_error(status)) return status;