ruby-changes:46078
From: nagachika <ko1@a...>
Date: Mon, 27 Mar 2017 21:27:05 +0900 (JST)
Subject: [ruby-changes:46078] nagachika:r58149 (ruby_2_3): merge revision(s) 57121: [Backport #13053]
nagachika 2017-03-27 21:26:59 +0900 (Mon, 27 Mar 2017) New Revision: 58149 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58149 Log: merge revision(s) 57121: [Backport #13053] array.c: do not resize to less than 0 Shrinking the Array from the block invoked by Array#select! or Array#reject! causes the Array to be a negative number size. Ensure that the resulting Array won't be smaller than 0. [ruby-core:78739] [Bug #13053] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/array.c branches/ruby_2_3/test/ruby/test_array.rb branches/ruby_2_3/version.h Index: ruby_2_3/array.c =================================================================== --- ruby_2_3/array.c (revision 58148) +++ ruby_2_3/array.c (revision 58149) @@ -2886,13 +2886,15 @@ select_bang_ensure(VALUE a) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/array.c#L2886 long len = RARRAY_LEN(ary); long i1 = arg->len[0], i2 = arg->len[1]; - if (i2 < i1) { + if (i2 < len && i2 < i1) { + long tail = 0; if (i1 < len) { + tail = len - i1; RARRAY_PTR_USE(ary, ptr, { - MEMMOVE(ptr + i2, ptr + i1, VALUE, len - i1); + MEMMOVE(ptr + i2, ptr + i1, VALUE, tail); }); } - ARY_SET_LEN(ary, len - i1 + i2); + ARY_SET_LEN(ary, i2 + tail); } return ary; } Index: ruby_2_3/test/ruby/test_array.rb =================================================================== --- ruby_2_3/test/ruby/test_array.rb (revision 58148) +++ ruby_2_3/test/ruby/test_array.rb (revision 58149) @@ -2125,6 +2125,11 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_array.rb#L2125 } assert_equal(9, r) assert_equal(@cls[7, 8, 9, 10], a, bug10722) + + bug13053 = '[ruby-core:78739] [Bug #13053] Array#select! can resize to negative size' + a = @cls[ 1, 2, 3, 4, 5 ] + a.select! {|i| a.clear if i == 5; false } + assert_equal(0, a.size, bug13053) end def test_delete2 Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 58148) +++ ruby_2_3/version.h (revision 58149) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.3" #define RUBY_RELEASE_DATE "2017-03-27" -#define RUBY_PATCHLEVEL 261 +#define RUBY_PATCHLEVEL 262 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r57121 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/