From 23995354d5e86ecf7c4ed1a7b1503b5751f75d44 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 4 Jan 2022 07:23:08 -0800 Subject: freeform: bug: account for consumed prefix. This was reported by user vapnik spaknik. The @(freeform), when reconstituting the unmatched trailing portion of the virtual line back into a list of lines, uses the abstract match position, neglecting to account for the fact that a prefix of the line may have been physically consumed to save memory. * match.c (v_freeform): When calling lazy_str_get_trailing_list, indicate the correct amount of prefix material, by subtracting, from the matching length, the base variable, which indicates how much of the prefix had been consumed. This consumption takes place above 4000 bytes, which is why the freeform test cases are not catching this. * tests/006/freeform-5.txr: New file. * tests/006/freeform-5.expected: New file. --- match.c | 2 +- tests/006/freeform-5.expected | 4 ++++ tests/006/freeform-5.txr | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/006/freeform-5.expected create mode 100644 tests/006/freeform-5.txr diff --git a/match.c b/match.c index 4dd19afc..0fab2920 100644 --- a/match.c +++ b/match.c @@ -2774,7 +2774,7 @@ static val v_freeform(match_files_ctx *c) } if (integerp(success)) { - c->data = lazy_str_get_trailing_list(mlc.dataline, success); + c->data = lazy_str_get_trailing_list(mlc.dataline, minus(success, mlc.base)); c->data_lineno = plus(c->data_lineno, one); } else if (success == t && lim) { c->data = lazy_str_get_trailing_list(mlc.dataline, length_str(mlc.dataline)); diff --git a/tests/006/freeform-5.expected b/tests/006/freeform-5.expected new file mode 100644 index 00000000..99433ca3 --- /dev/null +++ b/tests/006/freeform-5.expected @@ -0,0 +1,4 @@ +bar="BAR" +zzy="ZZY" +next="NEXT" +nextnext="NEXTNEXT" diff --git a/tests/006/freeform-5.txr b/tests/006/freeform-5.txr new file mode 100644 index 00000000..9e0aea40 --- /dev/null +++ b/tests/006/freeform-5.txr @@ -0,0 +1,8 @@ +@(next :list (append (repeat (list (mkstring 99 #\A)) 100) + '("FOOBARXYZZY" "NEXT" "NEXTNEXT"))) +@(freeform) +@(skip)FOO@{bar}XY +@zzy + +@next +@nextnext -- cgit v1.2.3