summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-01-04 07:23:08 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-01-04 07:23:08 -0800
commit23995354d5e86ecf7c4ed1a7b1503b5751f75d44 (patch)
tree51dedbc92c99ff5325077c2885555cedc91cfe27
parenteccac0d5e99577d1dac8bd9776ecf9f23e4c8ad8 (diff)
downloadtxr-23995354d5e86ecf7c4ed1a7b1503b5751f75d44.tar.gz
txr-23995354d5e86ecf7c4ed1a7b1503b5751f75d44.tar.bz2
txr-23995354d5e86ecf7c4ed1a7b1503b5751f75d44.zip
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.
-rw-r--r--match.c2
-rw-r--r--tests/006/freeform-5.expected4
-rw-r--r--tests/006/freeform-5.txr8
3 files changed, 13 insertions, 1 deletions
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