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

ruby-changes:36682

From: nobu <ko1@a...>
Date: Wed, 10 Dec 2014 21:10:00 +0900 (JST)
Subject: [ruby-changes:36682] nobu:r48763 (trunk): string.c: term fill

nobu	2014-12-10 21:09:49 +0900 (Wed, 10 Dec 2014)

  New Revision: 48763

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

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

  Modified files:
    trunk/string.c
    trunk/test/-ext-/string/test_cstr.rb
Index: string.c
===================================================================
--- string.c	(revision 48762)
+++ string.c	(revision 48763)
@@ -4158,7 +4158,7 @@ rb_str_sub_bang(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/string.c#L4158
 	memcpy(p + beg0, rp, rlen);
 	len += rlen - plen;
 	STR_SET_LEN(str, len);
-	RSTRING_PTR(str)[len] = '\0';
+	TERM_FILL(&RSTRING_PTR(str)[len], TERM_LEN(str));
 	ENC_CODERANGE_SET(str, cr);
 	if (tainted) OBJ_TAINT(str);
 
Index: test/-ext-/string/test_cstr.rb
===================================================================
--- test/-ext-/string/test_cstr.rb	(revision 48762)
+++ test/-ext-/string/test_cstr.rb	(revision 48763)
@@ -60,6 +60,10 @@ class Test_StringCStr < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_cstr.rb#L60
     assert_wchars_term_char("a"*30) {|s| s[29,1] = ""}
   end
 
+  def test_wchar_sub!
+    assert_wchars_term_char("foobar") {|s| s.sub!(/#{"foo".encode(s.encoding)}/, "")}
+  end
+
   def assert_wchars_term_char(str)
     result = {}
     WCHARS.map do |enc|

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

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