summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-08-24 06:28:39 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-08-24 06:28:39 -0700
commit3270a9ec78b00feb885b65915d020e60dd712a58 (patch)
treec91add01130f5109c6a0859f9f2dfb33fb13c21e
parenta150a76a6b2944f1415fb42281bf3d6eecfece48 (diff)
downloadtxr-3270a9ec78b00feb885b65915d020e60dd712a58.tar.gz
txr-3270a9ec78b00feb885b65915d020e60dd712a58.tar.bz2
txr-3270a9ec78b00feb885b65915d020e60dd712a58.zip
bugfix: replace_str uses string_extend incorrectly.
One test case for this is that (append "ABC" "DEF") returns an "ABCDEF" string whose length reports as 9 instead of the correct 6. This will wreak various havoc. The bug was introduced in the very first version of replace_str, in commit d011fda9b6b078f09027eb65d500c8beffc99414 on January 26, 2012. In the same commit, the string_extend behavior is introduced of supporting an integer value specifying the number of characters by which to extend the string. This feature of string_extend is used in replace_str, but wrongly. * lib.c (replace_str): Pass just the size delta to string_extend; do not add the old length to the delta such that the total size is wrongly passed.
-rw-r--r--lib.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 64387e17..657b39f3 100644
--- a/lib.c
+++ b/lib.c
@@ -3936,7 +3936,7 @@ val replace_str(val str_in, val items, val from, val to)
cnum t = c_num(to);
cnum l = c_num(len);
- string_extend(str_in, plus(len, len_diff));
+ string_extend(str_in, len_diff);
wmemmove(str_in->st.str + t + c_num(len_diff),
str_in->st.str + t, (l - t) + 1);
to = plus(from, len_it);