summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kazkylheku@vtech.ca>2021-04-13 07:26:46 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-04-13 07:26:46 -0700
commitc1ad83959110ff4c82af99eacbe9796148fadee5 (patch)
tree379fab4f7fa1b38ef919337ec2dc183d24bd5ca7
parentdb072d82063ae174493b1d6f57b49d54a9ec3ea8 (diff)
downloadtxr-c1ad83959110ff4c82af99eacbe9796148fadee5.tar.gz
txr-c1ad83959110ff4c82af99eacbe9796148fadee5.tar.bz2
txr-c1ad83959110ff4c82af99eacbe9796148fadee5.zip
regex: regsub wrongly destructive.
* regex.c (regsub): When the regex argument is actually a function, we must copy the string, because replace_str is destructive.
-rw-r--r--regex.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/regex.c b/regex.c
index e4a1e810..a0eecff8 100644
--- a/regex.c
+++ b/regex.c
@@ -2875,10 +2875,11 @@ val regsub(val regex, val repl, val str)
{
val rf = from(range);
val rt = to(range);
+ val scopy = copy_str(str);
- return replace_str(str, if3(isfunc,
- funcall1(repl, sub_str(str, rf, rt)),
- repl),
+ return replace_str(scopy, if3(isfunc,
+ funcall1(repl, sub_str(scopy, rf, rt)),
+ repl),
rf, rt);
}
} else {