diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-10 07:48:43 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-10 07:48:43 +0000 |
commit | 0c50d7ba1511cb89e7dd51e6f270725f07012a5b (patch) | |
tree | 3afea6e7e5fe79eb3e5eaa123437adba50184599 | |
parent | c00aca4aa0ccff7a579f5c711a04c495903b52e1 (diff) | |
download | ruby-0c50d7ba1511cb89e7dd51e6f270725f07012a5b.tar.gz |
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
-rw-r--r-- | string.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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); |