[前][次][番号順一覧][スレッド一覧]

ruby-changes:36678

From: nobu <ko1@a...>
Date: Wed, 10 Dec 2014 16:49:02 +0900 (JST)
Subject: [ruby-changes:36678] nobu:r48759 (trunk): string.c: term fill

nobu	2014-12-10 16:48:43 +0900 (Wed, 10 Dec 2014)

  New Revision: 48759

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48759

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

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 48758)
+++ string.c	(revision 48759)
@@ -1483,6 +1483,7 @@ rb_str_times(VALUE str, VALUE times) https://github.com/ruby/ruby/blob/trunk/string.c#L1483
     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) https://github.com/ruby/ruby/blob/trunk/string.c#L1493
 	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) https://github.com/ruby/ruby/blob/trunk/string.c#L1506
         }
         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);
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]