From 4d195751b4fd14fdff73e7026da92b497e174ff2 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 23 Jan 2024 23:53:34 -0600 Subject: [PATCH] Bugfix: Incorrect stop position is calculated when FSS content ends at the start position on FSS read operations. 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 | 9 +++++++- level_1/fl_fss/c/fss/basic_list.c | 31 +++++++++++++++++++++++----- level_1/fl_fss/c/fss/embedded_list.c | 22 ++++++++++++++++---- level_1/fl_fss/c/fss/extended_list.c | 22 ++++++++++++++++---- 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/level_1/fl_fss/c/fss/basic.c b/level_1/fl_fss/c/fss/basic.c index 0d58345b0..7dd98493f 100644 --- a/level_1/fl_fss/c/fss/basic.c +++ b/level_1/fl_fss/c/fss/basic.c @@ -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; diff --git a/level_1/fl_fss/c/fss/basic_list.c b/level_1/fl_fss/c/fss/basic_list.c index 440f583e9..e91b35e84 100644 --- a/level_1/fl_fss/c/fss/basic_list.c +++ b/level_1/fl_fss/c/fss/basic_list.c @@ -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; diff --git a/level_1/fl_fss/c/fss/embedded_list.c b/level_1/fl_fss/c/fss/embedded_list.c index dd241308e..fc53776e7 100644 --- a/level_1/fl_fss/c/fss/embedded_list.c +++ b/level_1/fl_fss/c/fss/embedded_list.c @@ -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; diff --git a/level_1/fl_fss/c/fss/extended_list.c b/level_1/fl_fss/c/fss/extended_list.c index 3860df287..f3eb721ee 100644 --- a/level_1/fl_fss/c/fss/extended_list.c +++ b/level_1/fl_fss/c/fss/extended_list.c @@ -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; -- 2.47.3