Get rid of undefined behavior

* string.c (rb_str_sub_bang): str and repl can be same.
  [Bug #15946]
This commit is contained in:
Nobuyoshi Nakada 2019-06-21 22:42:14 +09:00
parent 50841eca43
commit 8f51da5d41
No known key found for this signature in database
GPG Key ID: 4BC7D6DF58D8DF60

View File

@ -5087,7 +5087,7 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
if (rlen != plen) {
memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
}
memcpy(p + beg0, rp, rlen);
memmove(p + beg0, rp, rlen);
len += rlen - plen;
STR_SET_LEN(str, len);
TERM_FILL(&RSTRING_PTR(str)[len], TERM_LEN(str));