1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c: term fill

* string.c (rb_str_times): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-12-10 07:48:43 +00:00
parent c00aca4aa0
commit 0c50d7ba15

View file

@ -1483,6 +1483,7 @@ rb_str_times(VALUE str, VALUE times)
VALUE str2;
long n, len;
char *ptr2;
int termlen;
len = NUM2LONG(times);
if (len < 0) {
@ -1492,7 +1493,9 @@ rb_str_times(VALUE str, VALUE times)
rb_raise(rb_eArgError, "argument too big");
}
str2 = rb_str_new_with_class(str, 0, len *= RSTRING_LEN(str));
len *= RSTRING_LEN(str);
termlen = TERM_LEN(str);
str2 = rb_str_new_with_class(str, 0, (len + termlen - 1));
ptr2 = RSTRING_PTR(str2);
if (len) {
n = RSTRING_LEN(str);
@ -1503,7 +1506,8 @@ rb_str_times(VALUE str, VALUE times)
}
memcpy(ptr2 + n, ptr2, len-n);
}
ptr2[RSTRING_LEN(str2)] = '\0';
STR_SET_LEN(str2, len);
TERM_FILL(&ptr2[len], termlen);
OBJ_INFECT(str2, str);
rb_enc_cr_str_copy_for_substr(str2, str);