Replacing region may overwrap with the target region; fix #4627

This commit is contained in:
Yukihiro "Matz" Matsumoto
2019-08-12 16:51:01 +09:00
parent 472dba19ea
commit 285ce9d8aa
+1 -1
View File
@@ -1264,7 +1264,7 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb
memmove(strp + newlen - (len - end), strp + end, len - end);
if (!mrb_nil_p(rep)) {
memcpy(strp + pos, RSTRING_PTR(rep), replen);
memmove(strp + pos, RSTRING_PTR(rep), replen);
}
RSTR_SET_LEN(str, newlen);
strp[newlen] = '\0';