From 515f0bd24c83027472eee5a5b9405113a669b7b3 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 25 Mar 2022 21:34:34 -0500 Subject: [PATCH] Bugfix: Invalid content count in FSS Basic List. When F_none_eos or F_none_stop is returned, the content ends up having an additional size than the actual size. This is happening because found->used++ is incremented immediately before returning. When either F_none_eos or F_none_stop is returned, the content is not to be incremented. Only the caller should know when to assume this is a proper ending representing the content end. The macro private_macro_fl_fss_content_return_on_overflow_delimited() is only used in one place so remove it. Make sure to initialize the content for all content read functions to ensure the content count is consistent. --- level_1/fl_fss/c/fss/basic_list.c | 16 +++++++++++++--- level_1/fl_fss/c/fss/macro.h | 12 ------------ level_2/fll_fss/c/fss/basic.c | 2 ++ level_2/fll_fss/c/fss/basic_list.c | 2 ++ level_2/fll_fss/c/fss/embedded_list.c | 3 ++- level_2/fll_fss/c/fss/extended.c | 4 +++- level_2/fll_fss/c/fss/extended_list.c | 2 ++ level_2/fll_fss/c/fss/payload.c | 2 ++ 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/level_1/fl_fss/c/fss/basic_list.c b/level_1/fl_fss/c/fss/basic_list.c index 8441157..770d784 100644 --- a/level_1/fl_fss/c/fss/basic_list.c +++ b/level_1/fl_fss/c/fss/basic_list.c @@ -65,7 +65,7 @@ extern "C" { bool graph_first = F_true; - // identify where the object ends. + // Identify where the object ends. while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { if (state.interrupt) { @@ -538,9 +538,19 @@ extern "C" { return status; } - found->array[found->used++].stop = range->start - 1; + if (range->start >= buffer.used) { + found->array[found->used].stop = buffer.used - 1; + + return F_none_eos; + } + + if (range->start > range->stop) { + found->array[found->used].stop = range->stop; - private_macro_fl_fss_content_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop); + return F_none_stop; + } + + found->array[found->used++].stop = range->start - 1; return F_fss_found_content; } diff --git a/level_1/fl_fss/c/fss/macro.h b/level_1/fl_fss/c/fss/macro.h index c489f94..ab1835e 100644 --- a/level_1/fl_fss/c/fss/macro.h +++ b/level_1/fl_fss/c/fss/macro.h @@ -56,18 +56,6 @@ extern "C" { } #endif // _di_macro_fl_fss_content_with_comments_return_on_overflow_ -#ifndef _di_macro_fl_fss_content_return_on_overflow_delimited_ - #define private_macro_fl_fss_content_return_on_overflow_delimited(buffer, range, found, eos_status, stop_status) \ - if (range.start >= buffer.used) { \ - found.array[found.used].stop = buffer.used - 1; \ - return eos_status; \ - } \ - else if (range.start > range.stop) { \ - found.array[found.used].stop = range.stop; \ - return stop_status; \ - } -#endif // _di_macro_fl_fss_content_return_on_overflow_delimited_ - #ifndef _di_macro_fl_fss_nest_return_on_overflow_ #define private_macro_fl_fss_nest_return_on_overflow(buffer, range, found, delimits, delimits_used, comments, comments_used, positions, objects, slashes, eos_status, stop_status) \ if (range.start >= buffer.used) { \ diff --git a/level_2/fll_fss/c/fss/basic.c b/level_2/fll_fss/c/fss/basic.c index 51e5fb5..c1b6cc7 100644 --- a/level_2/fll_fss/c/fss/basic.c +++ b/level_2/fll_fss/c/fss/basic.c @@ -76,6 +76,8 @@ extern "C" { if (status == F_fss_found_object) { found_data = F_true; + contents->array[contents->used].used = 0; + status = fl_fss_basic_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits); if (F_status_is_error(status)) return status; diff --git a/level_2/fll_fss/c/fss/basic_list.c b/level_2/fll_fss/c/fss/basic_list.c index f19a4dd..85aa983 100644 --- a/level_2/fll_fss/c/fss/basic_list.c +++ b/level_2/fll_fss/c/fss/basic_list.c @@ -60,6 +60,8 @@ extern "C" { if (status == F_fss_found_object) { found_data = F_true; + contents->array[contents->used].used = 0; + status = fl_fss_basic_list_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments); if (F_status_is_error(status)) return status; diff --git a/level_2/fll_fss/c/fss/embedded_list.c b/level_2/fll_fss/c/fss/embedded_list.c index 006b1d1..6cd0d27 100644 --- a/level_2/fll_fss/c/fss/embedded_list.c +++ b/level_2/fll_fss/c/fss/embedded_list.c @@ -65,7 +65,8 @@ extern "C" { break; } - else if (status == F_fss_found_object_content_not) { + + if (status == F_fss_found_object_content_not) { found_data = F_true; break; diff --git a/level_2/fll_fss/c/fss/extended.c b/level_2/fll_fss/c/fss/extended.c index 98ad6bd..93ff506 100644 --- a/level_2/fll_fss/c/fss/extended.c +++ b/level_2/fll_fss/c/fss/extended.c @@ -88,6 +88,8 @@ extern "C" { if (status == F_fss_found_object) { found_data = F_true; + contents->array[contents->used].used = 0; + if (contents_quoted) { status2 = f_uint8s_increase(state.step_small, &contents_quoted->array[contents_quoted->used]); if (F_status_is_error(status2)) return status2; @@ -102,6 +104,7 @@ extern "C" { } else if (status == F_fss_found_object_content_not) { found_data = F_true; + break; } @@ -109,7 +112,6 @@ extern "C" { if (status == F_none_eos || status == F_none_stop) { contents->array[contents->used].used++; - ++objects->used; ++contents->used; diff --git a/level_2/fll_fss/c/fss/extended_list.c b/level_2/fll_fss/c/fss/extended_list.c index 4c7e85b..7330850 100644 --- a/level_2/fll_fss/c/fss/extended_list.c +++ b/level_2/fll_fss/c/fss/extended_list.c @@ -61,6 +61,8 @@ extern "C" { if (status == F_fss_found_object) { found_data = F_true; + contents->array[contents->used].used = 0; + status = fl_fss_extended_list_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments); if (F_status_is_error(status)) return status; diff --git a/level_2/fll_fss/c/fss/payload.c b/level_2/fll_fss/c/fss/payload.c index 35a1400..d333a50 100644 --- a/level_2/fll_fss/c/fss/payload.c +++ b/level_2/fll_fss/c/fss/payload.c @@ -70,6 +70,8 @@ extern "C" { if (status == F_fss_found_object) { found_data = F_true; + contents->array[contents->used].used = 0; + if (fl_string_dynamic_partial_compare_string(f_fss_string_payload_s.string, buffer, f_fss_string_payload_s.used, objects->array[objects->used]) == F_equal_to) { status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); if (F_status_is_error(status)) return status; -- 1.8.3.1