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

ruby-changes:37327

From: nobu <ko1@a...>
Date: Mon, 26 Jan 2015 12:43:27 +0900 (JST)
Subject: [ruby-changes:37327] nobu:r49408 (trunk): string.c: term fill

nobu	2015-01-26 12:43:20 +0900 (Mon, 26 Jan 2015)

  New Revision: 49408

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

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

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 49407)
+++ string.c	(revision 49408)
@@ -98,6 +98,9 @@ VALUE rb_cSymbol; https://github.com/ruby/ruby/blob/trunk/string.c#L98
 
 #define RESIZE_CAPA(str,capacity) do {\
     const int termlen = TERM_LEN(str);\
+    RESIZE_CAPA_TERM(str,capacity,termlen);\
+} while (0)
+#define RESIZE_CAPA_TERM(str,capacity,termlen) do {\
     if (STR_EMBED_P(str)) {\
 	if ((capacity) > RSTRING_EMBED_LEN_MAX) {\
 	    char *const tmp = ALLOC_N(char, (capacity)+termlen);\
@@ -2169,6 +2172,7 @@ str_buf_cat(VALUE str, const char *ptr, https://github.com/ruby/ruby/blob/trunk/string.c#L2172
 {
     long capa, total, olen, off = -1;
     char *sptr;
+    const int termlen = TERM_LEN(str);
 
     RSTRING_GETMEM(str, sptr, olen);
     if (ptr >= sptr && ptr <= sptr + olen) {
@@ -2198,7 +2202,7 @@ str_buf_cat(VALUE str, const char *ptr, https://github.com/ruby/ruby/blob/trunk/string.c#L2202
 	    }
 	    capa = 2 * capa;
 	}
-	RESIZE_CAPA(str, capa);
+	RESIZE_CAPA_TERM(str, capa, termlen);
 	sptr = RSTRING_PTR(str);
     }
     if (off != -1) {
@@ -2206,7 +2210,7 @@ str_buf_cat(VALUE str, const char *ptr, https://github.com/ruby/ruby/blob/trunk/string.c#L2210
     }
     memcpy(sptr + olen, ptr, len);
     STR_SET_LEN(str, total);
-    RSTRING_PTR(str)[total] = '\0'; /* sentinel */
+    TERM_FILL(sptr + total, termlen); /* sentinel */
 
     return str;
 }

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

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