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

ruby-changes:33455

From: nobu <ko1@a...>
Date: Wed, 9 Apr 2014 12:45:03 +0900 (JST)
Subject: [ruby-changes:33455] nobu:r45534 (trunk): string.c: fix capacity

nobu	2014-04-09 12:44:55 +0900 (Wed, 09 Apr 2014)

  New Revision: 45534

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

  Log:
    string.c: fix capacity
    
    * string.c (str_buf_cat): should round up the capacity by 4KiB,
      but not number of rooms.  [ruby-core:61886] [Bug #9709]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45533)
+++ ChangeLog	(revision 45534)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr  9 12:44:54 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (str_buf_cat): should round up the capacity by 4KiB,
+	  but not number of rooms.  [ruby-core:61886] [Bug #9709]
+
 Tue Apr  8 22:55:32 2014  Akinori MUSHA  <knu@i...>
 
 	* lib/mkmf.rb (MakeMakefile#dir_config): Improve documentation.
Index: string.c
===================================================================
--- string.c	(revision 45533)
+++ string.c	(revision 45534)
@@ -2029,7 +2029,7 @@ str_buf_cat(VALUE str, const char *ptr, https://github.com/ruby/ruby/blob/trunk/string.c#L2029
     if (capa <= total) {
 	while (total > capa) {
 	    if (capa + termlen >= LONG_MAX / 2) {
-		capa = (total + 4095) / 4096;
+		capa = (total + 4095) / 4096 * 4096;
 		break;
 	    }
 	    capa = (capa + termlen) * 2;
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 45533)
+++ test/ruby/test_string.rb	(revision 45534)
@@ -2252,6 +2252,17 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L2252
     assert_equal(:foo, s.send(:=~, /abc/))
     assert_equal(:foo, s =~ /abc/, "should not use optimized instruction")
   end
+
+  def test_LSHIFT_neary_long_max
+    return unless @cls == String
+    assert_ruby_status([], <<-'end;', '[ruby-core:61886] [Bug #9709]')
+      begin
+        a = "a" * 0x4000_0000
+        a << "a" * 0x1_0000
+      rescue NoMemoryError
+      end
+    end;
+  end
 end
 
 class TestString2 < TestString

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

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