From: Kevin Day Date: Wed, 24 Jan 2024 05:54:07 +0000 (-0600) Subject: Bugfix: Incorrect stop position is calculated when FSS content ends at the start... X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=ba257a8b8385ec8dedfc9bc9bb596e420ca552f8;p=fll 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. --- diff --git a/level_1/fl_fss/c/fss/basic.c b/level_1/fl_fss/c/fss/basic.c index a679642..d198944 100644 --- a/level_1/fl_fss/c/fss/basic.c +++ b/level_1/fl_fss/c/fss/basic.c @@ -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; diff --git a/level_1/fl_fss/c/fss/basic_list.c b/level_1/fl_fss/c/fss/basic_list.c index cd937a0..aab99da 100644 --- a/level_1/fl_fss/c/fss/basic_list.c +++ b/level_1/fl_fss/c/fss/basic_list.c @@ -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; diff --git a/level_1/fl_fss/c/fss/embedded_list.c b/level_1/fl_fss/c/fss/embedded_list.c index dcae894..0f21132 100644 --- a/level_1/fl_fss/c/fss/embedded_list.c +++ b/level_1/fl_fss/c/fss/embedded_list.c @@ -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; diff --git a/level_1/fl_fss/c/fss/extended_list.c b/level_1/fl_fss/c/fss/extended_list.c index 3d4c71e..755b213 100644 --- a/level_1/fl_fss/c/fss/extended_list.c +++ b/level_1/fl_fss/c/fss/extended_list.c @@ -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; diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index 7385d41..26365c7 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -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]) {