diff --git a/ChangeLog b/ChangeLog index 19b3a23608..aad8154fec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 9 19:40:03 2012 NARUSE, Yui + + * array.c (rb_ary_splice): fix r37583 doesn't condier the case when + beg > array length. + Fri Nov 9 16:11:58 2012 Nobuyoshi Nakada * random.c (rb_memhash): use siphash. diff --git a/array.c b/array.c index 072180dc86..df0a0a43aa 100644 --- a/array.c +++ b/array.c @@ -1438,7 +1438,7 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl) if (beg > ARY_MAX_SIZE - rlen) { rb_raise(rb_eIndexError, "index %ld too big", beg); } - ary_ensure_room_for_push(ary, rlen); + ary_ensure_room_for_push(ary, rlen-len); /* len is 0 or negative */ len = beg + rlen; rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary), beg - RARRAY_LEN(ary)); if (rlen > 0) { diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index b0e7058b5b..8d264d9230 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -426,6 +426,18 @@ class TestArray < Test::Unit::TestCase a = @cls[1, 2, 3] a[-1, 0] = a assert_equal([1, 2, 1, 2, 3, 3], a) + + a = @cls[] + a[5,0] = [5] + assert_equal([nil, nil, nil, nil, nil, 5], a) + + a = @cls[1] + a[1,0] = [2] + assert_equal([1, 2], a) + + a = @cls[1] + a[1,1] = [2] + assert_equal([1, 2], a) end def test_assoc