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.
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) {
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;
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;
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_
}
// Begin the search.
+ const f_number_unsigned_t begin = range->start;
found->start = range->start;
// Ignore all comment lines.
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;
}
} // 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;
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;
}
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;
}
// Begin the search.
+ const f_number_unsigned_t begin = range->start;
found->start = range->start;
// Ignore all comment lines.
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) {
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;
}
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;
}
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;
}
// Begin the search.
+ const f_number_unsigned_t begin = range->start;
found->start = range->start;
// Ignore all comment lines.
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) {
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;
}
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;
}
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;
}
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;
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.
// 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;
}
}
- 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;
// 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.
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]) {