]> Kevux Git Server - fll/commitdiff
Bugfix: Incorrect stop position is calculated when FSS content ends at the start...
authorKevin Day <kevin@kevux.org>
Wed, 24 Jan 2024 05:54:07 +0000 (23:54 -0600)
committerKevin Day <kevin@kevux.org>
Wed, 24 Jan 2024 05:54:07 +0000 (23:54 -0600)
When the start position is say, 0, and the determined stop position ends up being 0, then an incorrect stop range is calculated.
This happens because the stop position is subtracting one from the current position.

Add checks to ensure that the stop position is never subtracted beyond the initial start position.

The initial start position is saved at the beginning of each affected FSS read function.

This now potentially returns a start range before the stop range.
The FSS read programs should also need to be updated following this commit to handle these cases.

level_1/fl_fss/c/fss/basic.c
level_1/fl_fss/c/fss/basic_list.c
level_1/fl_fss/c/fss/embedded_list.c
level_1/fl_fss/c/fss/extended_list.c
level_1/fl_fss/c/private-fss.c

index a6796420080b77dc8431e2bd092a6e57f39f5db6..d19894434719e09d2c23b78746c436f0dbe96cf3 100644 (file)
@@ -43,6 +43,7 @@ extern "C" {
     state->status = f_memory_array_increase(state->step_small, sizeof(f_range_t), (void **) &found->array, &found->used, &found->size);
     if (F_status_is_error(state->status)) return;
 
+    const f_number_unsigned_t begin = range->start;
     found->array[found->used].start = range->start;
 
     for (;; ++range->start) {
@@ -61,7 +62,13 @@ extern "C" {
 
     if (F_status_is_error(state->status)) return;
 
-    found->array[found->used++].stop = range->start - 1;
+    if (range->start > begin) {
+      found->array[found->used++].stop = range->start - 1;
+    }
+    else {
+      found->array[found->used].start = 1;
+      found->array[found->used++].stop = 0;
+    }
 
     state->status = f_utf_buffer_increment(buffer, range, 1);
     if (F_status_is_error(state->status)) return;
index cd937a04f6be98f9fb3c1d4dbc26a97e8b0e5c80..aab99da8e3e45d2fecfddfbe246f2852b3f58d98 100644 (file)
@@ -43,6 +43,7 @@ extern "C" {
     state->status = f_memory_array_increase(state->step_small, sizeof(f_range_t), (void **) &found->array, &found->used, &found->size);
     if (F_status_is_error(state->status)) return;
 
+    const f_number_unsigned_t begin = range->start;
     found->array[found->used].start = range->start;
 
     f_number_unsigned_t newline_last = range->start;
@@ -285,7 +286,14 @@ extern "C" {
       return;
     }
 
-    found->array[found->used++].stop = range->start - 1;
+    if (range->start > begin) {
+      found->array[found->used++].stop = range->start - 1;
+    }
+    else {
+      found->array[found->used].start = 1;
+      found->array[found->used++].stop = 0;
+    }
+
     state->status = F_fss_found_content;
   }
 #endif // _di_fl_fss_basic_list_content_read_
@@ -579,6 +587,7 @@ extern "C" {
     }
 
     // Begin the search.
+    const f_number_unsigned_t begin = range->start;
     found->start = range->start;
 
     // Ignore all comment lines.
@@ -655,7 +664,7 @@ extern "C" {
 
         if (buffer.string[range->start] == f_fss_basic_list_open_s.string[0]) {
           graph_first = F_false;
-          stop = range->start - 1;
+          stop = range->start;
 
           state->status = f_utf_buffer_increment(buffer, range, 1);
           if (F_status_is_error(state->status)) return;
@@ -723,7 +732,14 @@ extern "C" {
                 }
               } // while
 
-              found->stop = stop;
+              if (stop > begin) {
+                found->stop = stop - 1;
+              }
+              else {
+                found->start = 1;
+                found->stop = 0;
+              }
+
               range->start = start + 1;
               state->status = F_fss_found_object;
 
@@ -755,7 +771,7 @@ extern "C" {
 
       if (buffer.string[range->start] == f_fss_basic_list_open_s.string[0]) {
         graph_first = F_false;
-        stop = range->start - 1;
+        stop = range->start;
 
         state->status = f_utf_buffer_increment(buffer, range, 1);
         if (F_status_is_error(state->status)) break;
@@ -794,7 +810,13 @@ extern "C" {
         }
 
         if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
-          found->stop = stop;
+          if (stop > begin) {
+            found->stop = stop - 1;
+          }
+          else {
+            found->start = 1;
+            found->stop = 0;
+          }
 
           state->status = f_utf_buffer_increment(buffer, range, 1);
           if (F_status_is_error(state->status)) break;
index dcae894071184bd77dcb6cf1180760b69537fab8..0f21132bace3b2759cabc9c1b24f0cce1558dc49 100644 (file)
@@ -1136,6 +1136,7 @@ extern "C" {
     }
 
     // Begin the search.
+    const f_number_unsigned_t begin = range->start;
     found->start = range->start;
 
     // Ignore all comment lines.
@@ -1221,7 +1222,7 @@ extern "C" {
 
         if (buffer.string[range->start] == f_fss_embedded_list_open_s.string[0]) {
           graph_first = F_false;
-          stop = range->start++ - 1;
+          stop = range->start++;
 
           while (range->start <= range->stop && range->start < buffer.used) {
 
@@ -1283,7 +1284,14 @@ extern "C" {
 
               if (F_status_is_error(state->status)) break;
 
-              found->stop = stop;
+              if (stop > begin) {
+                found->stop = stop - 1;
+              }
+              else {
+                found->start = 1;
+                found->stop = 0;
+              }
+
               range->start = start + 1;
               state->status = F_fss_found_object;
 
@@ -1314,7 +1322,7 @@ extern "C" {
       }
       else if (buffer.string[range->start] == f_fss_embedded_list_open_s.string[0]) {
         graph_first = F_false;
-        stop = range->start - 1;
+        stop = range->start;
 
         state->status = f_utf_buffer_increment(buffer, range, 1);
         if (F_status_is_error(state->status)) break;
@@ -1355,7 +1363,13 @@ extern "C" {
         }
 
         if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
-          found->stop = stop;
+          if (stop > begin) {
+            found->stop = stop - 1;
+          }
+          else {
+            found->start = 1;
+            found->stop = 0;
+          }
 
           // Move the start position to after the EOL.
           ++range->start;
index 3d4c71ef54c50adc3e12319186153fd47ee36d2d..755b2133ce939b2109935c6509ecd14e019b57fd 100644 (file)
@@ -577,6 +577,7 @@ extern "C" {
     }
 
     // Begin the search.
+    const f_number_unsigned_t begin = range->start;
     found->start = range->start;
 
     // Ignore all comment lines.
@@ -662,7 +663,7 @@ extern "C" {
 
         if (buffer.string[range->start] == f_fss_extended_list_open_s.string[0]) {
           graph_first = F_false;
-          stop = range->start++ - 1;
+          stop = range->start++;
 
           while (range->start <= range->stop && range->start < buffer.used) {
 
@@ -692,7 +693,14 @@ extern "C" {
               state->status = F_data_not_eos;
             }
             else {
-              found->stop = range->stop;
+              if (stop > begin) {
+                found->stop = stop - 1;
+              }
+              else {
+                found->start = 1;
+                found->stop = 0;
+              }
+
               state->status =  F_data_not_stop;
             }
 
@@ -723,7 +731,14 @@ extern "C" {
 
               if (F_status_is_error(state->status)) break;
 
-              found->stop = stop;
+              if (stop > begin) {
+                found->stop = stop - 1;
+              }
+              else {
+                found->start = 1;
+                found->stop = 0;
+              }
+
               range->start = start + 1;
               state->status = F_fss_found_object;
 
@@ -754,7 +769,7 @@ extern "C" {
       }
       else if (buffer.string[range->start] == f_fss_extended_list_open_s.string[0]) {
         graph_first = F_false;
-        stop = range->start - 1;
+        stop = range->start;
 
         state->status = f_utf_buffer_increment(buffer, range, 1);
         if (F_status_is_error(state->status)) break;
@@ -795,7 +810,13 @@ extern "C" {
         }
 
         if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
-          found->stop = stop;
+          if (stop > begin) {
+            found->stop = stop - 1;
+          }
+          else {
+            found->start = 1;
+            found->stop = 0;
+          }
 
           // Move the start position to after the EOL.
           ++range->start;
index 7385d41776a47a97f70cc82594b3f62ce5c25d3b..26365c728a8525933a731a5d4c1ff4f18a36081d 100644 (file)
@@ -142,6 +142,7 @@ extern "C" {
     const f_number_unsigned_t delimits_used = delimits->used;
 
     // Begin the search.
+    const f_number_unsigned_t begin = range->start;
     found->start = range->start;
 
     // Ignore all comment lines.
@@ -216,7 +217,13 @@ extern "C" {
 
           // Found the end of the object while processing the slash for potential delimits.
           if (state->status == F_true) {
-            found->stop = range->start - 1;
+            if (range->start > begin) {
+              found->stop = range->start - 1;
+            }
+            else {
+              found->start = 1;
+              found->stop = 0;
+            }
 
             state->status = f_utf_buffer_increment(buffer, range, 1);
             if (F_status_is_error(state->status)) break;
@@ -552,7 +559,13 @@ extern "C" {
               }
             }
 
-            found->stop = range->start - 1;
+            if (range->start > begin) {
+              found->stop = range->start - 1;
+            }
+            else {
+              found->start = 1;
+              found->stop = 0;
+            }
 
             state->status = f_utf_buffer_increment(buffer, range, 1);
             if (F_status_is_error(state->status)) return;
@@ -642,8 +655,15 @@ extern "C" {
 
           // The quote is incomplete, so treat the entire line as the Object as per the specification (including the quotes).
           // The error bit is set to designate that the Object is found in an erroneous state (not having a terminating quote).
-          found->start -= 1;
-          found->stop = range->start - 1;
+          if (found->start > begin && range->start > begin) {
+            found->start -= 1;
+            found->stop = range->start - 1;
+          }
+          else {
+            found->start = 1;
+            found->stop = 0;
+          }
+
           state->status = F_status_set_error(F_fss_found_object_content_not);
 
           // The delimits cannot be preserved in this case as per specification.
@@ -696,7 +716,13 @@ extern "C" {
 
       if (F_status_is_error(state->status)) return;
 
-      found->stop = range->start - 1;
+      if (range->start > begin) {
+        found->stop = range->start - 1;
+      }
+      else {
+        found->start = 1;
+        found->stop = 0;
+      }
 
       if (buffer.string[range->start] == f_fss_eol_s.string[0]) {