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:
parent
c00aca4aa0
commit
0c50d7ba15
1 changed files with 6 additions and 2 deletions
8
string.c
8
string.c
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue