]> 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:53:34 +0000 (23:53 -0600)
committerKevin Day <kevin@kevux.org>
Wed, 24 Jan 2024 05:53:34 +0000 (23:53 -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

index 0d58345b073a76a3bb5fb01389c04779b7dbb191..7dd98493f105931c7173166f098acb65803c9d59 100644 (file)
@@ -29,6 +29,7 @@ extern "C" {
     status = f_string_ranges_increase(state.step_small, found);
     if (F_status_is_error(status)) return status;
 
+    const f_number_unsigned_t begin = range->start;
     found->array[found->used].start = range->start;
 
     for (;; ++range->start) {
@@ -52,7 +53,13 @@ extern "C" {
 
     if (F_status_is_error(status)) return status;
 
-    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;
+    }
 
     status = f_utf_buffer_increment(buffer, range, 1);
     if (F_status_is_error(status)) return status;
index 440f583e954f025508e6d616118c6b11a2b664a7..e91b35e84c4be40d447e2d62a03c7bfbcf0699d4 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
     status = f_string_ranges_increase(state.step_small, found);
     if (F_status_is_error(status)) return status;
 
+    const f_number_unsigned_t begin = range->start;
     found->array[found->used].start = range->start;
 
     f_array_length_t newline_last = range->start;
@@ -283,7 +284,13 @@ extern "C" {
       return F_none_stop;
     }
 
-    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;
+    }
 
     return F_fss_found_content;
   }
@@ -559,6 +566,7 @@ extern "C" {
     if (status == F_none_stop) return F_data_not_stop;
 
     // Begin the search.
+    const f_number_unsigned_t begin = range->start;
     found->start = range->start;
 
     // Ignore all comment lines.
@@ -625,7 +633,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;
 
           status = f_utf_buffer_increment(buffer, range, 1);
           if (F_status_is_error(status)) return status;
@@ -684,7 +692,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;
 
               return F_fss_found_object;
@@ -714,7 +729,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;
 
         status = f_utf_buffer_increment(buffer, range, 1);
         if (F_status_is_error(status)) break;
@@ -745,7 +760,13 @@ extern "C" {
         private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
 
         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;
+          }
 
           status = f_utf_buffer_increment(buffer, range, 1);
           if (F_status_is_error(status)) break;
index dd241308ecbd5cc56a82b8cf602ae7eaa4e9fac2..fc53776e7ecb8ab8d6e551122edb5ed44f6d20f0 100644 (file)
@@ -987,6 +987,7 @@ extern "C" {
     }
 
     // Begin the search.
+    const f_number_unsigned_t begin = range->start;
     found->start = range->start;
 
     // Ignore all comment lines.
@@ -1059,7 +1060,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) {
 
@@ -1111,7 +1112,14 @@ extern "C" {
 
               if (F_status_is_error(status)) break;
 
-              found->stop = stop;
+              if (stop > begin) {
+                found->stop = stop - 1;
+              }
+              else {
+                found->start = 1;
+                found->stop = 0;
+              }
+
               range->start = start + 1;
 
               return F_fss_found_object;
@@ -1139,7 +1147,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;
 
         status = f_utf_buffer_increment(buffer, range, 1);
         if (F_status_is_error(status)) break;
@@ -1172,7 +1180,13 @@ extern "C" {
         private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
 
         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 3860df28761bc69b04887dd4edc12d9ca98cdad5..f3eb721eedfeece0d07efab5099e6fe4bc26f6ab 100644 (file)
@@ -548,6 +548,7 @@ extern "C" {
     }
 
     // Begin the search.
+    const f_number_unsigned_t begin = range->start;
     found->start = range->start;
 
     // Ignore all comment lines.
@@ -620,7 +621,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) {
 
@@ -671,7 +672,14 @@ extern "C" {
 
               if (F_status_is_error(status)) break;
 
-              found->stop = stop;
+              if (stop > begin) {
+                found->stop = stop - 1;
+              }
+              else {
+                found->start = 1;
+                found->stop = 0;
+              }
+
               range->start = start + 1;
 
               return F_fss_found_object;
@@ -700,7 +708,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;
 
         status = f_utf_buffer_increment(buffer, range, 1);
         if (F_status_is_error(status)) break;
@@ -733,7 +741,13 @@ extern "C" {
         private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
 
         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;