From 68537a42198a8ef6ef3699527ebfdf05989676a4 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 Apr 2014 03:44:55 +0000 Subject: 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ string.c | 2 +- test/ruby/test_string.rb | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6d1ceb6cba..309a5556fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Apr 9 12:44:54 2014 Nobuyoshi Nakada + + * 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 * lib/mkmf.rb (MakeMakefile#dir_config): Improve documentation. diff --git a/string.c b/string.c index 511374c7b8..ccf265738e 100644 --- a/string.c +++ b/string.c @@ -2029,7 +2029,7 @@ str_buf_cat(VALUE str, const char *ptr, long len) 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; diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index a35f6a3bb7..8366424c66 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -2252,6 +2252,17 @@ class TestString < Test::Unit::TestCase 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 -- cgit v1.2.3