From 93994704ebceb74b7a712166bbe757821ed007db Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 24 Aug 2024 23:30:44 -0500 Subject: [PATCH] Bugfix: Invalid comment handling in FSS Embedded Read. The comments are not being properly processed because graph_first is not and should be being set to 0x1 at start. As a result, the first comment is not being treated as a comment. Make sure to reset the `graph_first` and `line_start` after processing the comment. The comment starts at the line and so use `line_start` rather than `newline_last + 1`. Remove dead code where `graph_first == 0x2` is being checked inside a block that requires `graph_first` to be `0x1`. Update code comments about `graph_first` in several of the fl_fss read sources. Add additional check for buffer string range when processing comments. Update the runtime tests as appropriate. I also noticed that several of these runtime tests use `--line` but are showing multiple lines. I will address this bug in a separate commit. --- level_1/fl_fss/c/fss/basic_list.c | 4 +++- level_1/fl_fss/c/fss/embedded_list.c | 16 ++++++---------- level_1/fl_fss/c/fss/extended_list.c | 3 ++- level_3/fss_embedded_list_read/c/private-read.c | 5 ++++- ...\262\320\265\321\202_has_space-select-0-total.expect" | 2 +- ...70\320\262\320\265\321\202_has_space-select-0.expect" | 1 - ...0\270\320\262\320\265\321\202_has_space-total.expect" | 2 +- ...200\320\270\320\262\320\265\321\202_has_space.expect" | 1 - .../expect/test-0002-mixed-content-original.expect | 1 - .../test-0002-mixed-content-select-0-original.expect | 1 - .../expect/test-0002-mixed-content-select-0.expect | 1 - .../fss_0008/expect/test-0002-mixed-content-total.expect | 2 +- .../fss_0008/expect/test-0002-mixed-content-trim.expect | 1 - .../fss_0008/expect/test-0002-mixed-content.expect | 1 - .../test-0002-mixed-object_and_content-line-0.expect | 1 - .../test-0002-mixed-object_and_content-line-1.expect | 1 - .../test-0002-mixed-object_and_content-line-100.expect | 1 - .../test-0002-mixed-object_and_content-line-5.expect | 1 - .../test-0002-mixed-object_and_content-line-6.expect | 1 - ...70\320\262\320\265\321\202_has_space-select-0.expect" | 1 - ...0\270\320\262\320\265\321\202_has_space-total.expect" | 2 +- .../test-0002-mixed-object_and_content-original.expect | 1 - .../test-0002-mixed-object_and_content-select-0.expect | 1 - .../test-0002-mixed-object_and_content-total.expect | 2 +- .../test-0002-mixed-object_and_content-trim.expect | 1 - .../expect/test-0002-mixed-object_and_content.expect | 1 - 26 files changed, 20 insertions(+), 35 deletions(-) diff --git a/level_1/fl_fss/c/fss/basic_list.c b/level_1/fl_fss/c/fss/basic_list.c index 7ae97ab..2f7504f 100644 --- a/level_1/fl_fss/c/fss/basic_list.c +++ b/level_1/fl_fss/c/fss/basic_list.c @@ -35,7 +35,9 @@ extern "C" { f_array_length_t start = 0; f_array_length_t comment_delimit = 0; - uint8_t graph_first = 0x1; // 0x0 = false, 0x1 = true, 0x2 = false, but there is a delimited comment, comment_delimit is set. + // Designate that this is the first graph character. + // 0x0 = false, 0x1 = true, 0x2 = false, but there is a delimited comment, comment_delimit is set. + uint8_t graph_first = 0x1; // Identify where the content ends. while (range->start <= range->stop && range->start < buffer.used) { diff --git a/level_1/fl_fss/c/fss/embedded_list.c b/level_1/fl_fss/c/fss/embedded_list.c index 261a36f..8ea4479 100644 --- a/level_1/fl_fss/c/fss/embedded_list.c +++ b/level_1/fl_fss/c/fss/embedded_list.c @@ -69,8 +69,9 @@ extern "C" { bool is_open = F_false; + // Designate that this is the first graph character. // 0x0 = false, 0x1 = true, 0x2 = false, but there is a delimited comment, comment_delimit is set. - uint8_t graph_first = 0x0; + uint8_t graph_first = 0x1; // Initialize depth 1 start position. // Positions_start.used is used as a max depth (such that positions_start.used == max depth + 1). @@ -598,7 +599,7 @@ extern "C" { } } else if (graph_first == 0x1 && buffer.string[range->start] == f_fss_comment_s.string[0]) { - position = newline_last + 1; + position = line_start; status = f_fss_seek_to_eol(state, buffer, range); if (F_status_is_error(status)) break; @@ -610,19 +611,14 @@ extern "C" { --range->start; } else { - if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; - - delimits->array[delimits->used++] = comment_delimit; - } - newline_last = range->start; - graph_first = 0x1; } + graph_first = 0x1; + comments->array[comments->used].start = position; comments->array[comments->used++].stop = range->start++; + line_start = range->start; continue; } diff --git a/level_1/fl_fss/c/fss/extended_list.c b/level_1/fl_fss/c/fss/extended_list.c index 9a7ae4b..875f104 100644 --- a/level_1/fl_fss/c/fss/extended_list.c +++ b/level_1/fl_fss/c/fss/extended_list.c @@ -582,7 +582,8 @@ extern "C" { f_array_length_t slash_first = 0; f_array_length_t slash_count = 0; - bool graph_first = F_true; + // Designate that this is the first graph character. + uint8_t graph_first = F_true; // Identify where the object ends. while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { diff --git a/level_3/fss_embedded_list_read/c/private-read.c b/level_3/fss_embedded_list_read/c/private-read.c index 69cfb68..43b76bb 100644 --- a/level_3/fss_embedded_list_read/c/private-read.c +++ b/level_3/fss_embedded_list_read/c/private-read.c @@ -279,7 +279,10 @@ extern "C" { for (; i < comments->used; ++i) { for (j = comments->array[i].start; j <= comments->array[i].stop; ++j) { - data->buffer.string[j] = f_fss_delimit_placeholder_s.string[0]; + + if (j < data->buffer.used) { + data->buffer.string[j] = f_fss_delimit_placeholder_s.string[0]; + } } // for } // for } diff --git "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0-total.expect" "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0-total.expect" index 0cfbf08..d00491f 100644 --- "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0-total.expect" +++ "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0-total.expect" @@ -1 +1 @@ -2 +1 diff --git "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" index 29ae14d..9965c73 100644 --- "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" +++ "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" @@ -1,2 +1 @@ - # has a comment But this is not a comment. diff --git "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" index 0cfbf08..d00491f 100644 --- "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" +++ "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" @@ -1 +1 @@ -2 +1 diff --git "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space.expect" "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space.expect" index 29ae14d..9965c73 100644 --- "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space.expect" +++ "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space.expect" @@ -1,2 +1 @@ - # has a comment But this is not a comment. diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-original.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-original.expect index 53d1e7a..959ccee 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-original.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-original.expect @@ -9,7 +9,6 @@ c d with content. another "A" list. quoted, "yep". - # has a comment But this is not a comment. not a list\: a b привет diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0-original.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0-original.expect index 53d1e7a..959ccee 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0-original.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0-original.expect @@ -9,7 +9,6 @@ c d with content. another "A" list. quoted, "yep". - # has a comment But this is not a comment. not a list\: a b привет diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0.expect index bbd7eb3..9c5c57b 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-select-0.expect @@ -9,7 +9,6 @@ c d with content. another "A" list. quoted, "yep". - # has a comment But this is not a comment. not a list\: a b привет diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-total.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-total.expect index 209e3ef..d6b2404 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-total.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-total.expect @@ -1 +1 @@ -20 +19 diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-trim.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-trim.expect index bbd7eb3..9c5c57b 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-trim.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content-trim.expect @@ -9,7 +9,6 @@ c d with content. another "A" list. quoted, "yep". - # has a comment But this is not a comment. not a list\: a b привет diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content.expect index bbd7eb3..9c5c57b 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-content.expect @@ -9,7 +9,6 @@ c d with content. another "A" list. quoted, "yep". - # has a comment But this is not a comment. not a list\: a b привет diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-0.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-0.expect index 9d794f3..0a7c3b0 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-0.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-0.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-1.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-1.expect index 9d794f3..0a7c3b0 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-1.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-1.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-100.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-100.expect index 9d794f3..0a7c3b0 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-100.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-100.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-5.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-5.expect index 9d794f3..0a7c3b0 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-5.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-5.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-6.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-6.expect index 9d794f3..0a7c3b0 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-6.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-line-6.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" index fad0fdc..171efdd 100644 --- "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" +++ "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-select-0.expect" @@ -1,4 +1,3 @@ привет has space{ - # has a comment But this is not a comment. } diff --git "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" index b8626c4..00750ed 100644 --- "a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" +++ "b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-name-\320\277\321\200\320\270\320\262\320\265\321\202_has_space-total.expect" @@ -1 +1 @@ -4 +3 diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-original.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-original.expect index 501583e..025cdb4 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-original.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-original.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-select-0.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-select-0.expect index 9d794f3..0a7c3b0 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-select-0.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-select-0.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-total.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-total.expect index a787364..bb95160 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-total.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-total.expect @@ -1 +1 @@ -34 +33 diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-trim.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-trim.expect index 84340a2..8ac8e0e 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-trim.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content-trim.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ diff --git a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content.expect b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content.expect index 9d794f3..0a7c3b0 100644 --- a/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content.expect +++ b/level_3/fss_embedded_list_read/tests/runtime/fss_0008/expect/test-0002-mixed-object_and_content.expect @@ -16,7 +16,6 @@ a{ quoted, "yep". } привет has space{ - # has a comment But this is not a comment. } empty{ -- 1.8.3.1