From 3270a9ec78b00feb885b65915d020e60dd712a58 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 24 Aug 2017 06:28:39 -0700 Subject: 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. --- lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); -- cgit v1.2.3