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

parent 472dba19
...@@ -1264,7 +1264,7 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb ...@@ -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); memmove(strp + newlen - (len - end), strp + end, len - end);
if (!mrb_nil_p(rep)) { if (!mrb_nil_p(rep)) {
memcpy(strp + pos, RSTRING_PTR(rep), replen); memmove(strp + pos, RSTRING_PTR(rep), replen);
} }
RSTR_SET_LEN(str, newlen); RSTR_SET_LEN(str, newlen);
strp[newlen] = '\0'; strp[newlen] = '\0';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment