Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* array.c (rb_ary_splice): fix r37583 doesn't condier the case when

  beg > array length.
  • Loading branch information...
commit eeccf2aa82a06ef118f51152eafc30ac16063d1c 1 parent 2cfa09e
NARUSE, Yui nurse authored committed
Showing with 13 additions and 1 deletion.
  1. +1 −1  array.c
  2. +12 −0 test/ruby/test_array.rb
2  array.c
View
@@ -1395,7 +1395,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) {
12 test/ruby/test_array.rb
View
@@ -414,6 +414,18 @@ def test_ASET # '[]='
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
Please sign in to comment.
Something went wrong with that request. Please try again.