summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-05 03:13:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-05 03:13:32 +0000
commita7d8042774c4850f91947711f7a85067a2e7af01 (patch)
tree69a927a646cda337060399a2a8c3b08976f3bdcb
parent646988189a1e3768ac9247de84f32b6460b2cfbb (diff)
* array.c (rb_ary_slice_bang): should adjust length before making
sub-array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--array.c3
2 files changed, 8 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 346d1e31e1c..25a48602fb2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon May 5 12:12:11 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * array.c (rb_ary_slice_bang): should adjust length before making
+ sub-array.
+
Mon May 5 11:36:14 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_dup): should dupe corresponding information.
diff --git a/array.c b/array.c
index 39317986211..fcd030b5938 100644
--- a/array.c
+++ b/array.c
@@ -1794,6 +1794,9 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
pos = RARRAY_LEN(ary) + pos;
if (pos < 0) return Qnil;
}
+ if (RARRAY_LEN(ary) < len || RARRAY_LEN(ary) < pos + len) {
+ len = RARRAY_LEN(ary) - pos;
+ }
arg2 = rb_ary_new4(len, RARRAY_PTR(ary)+pos);
RBASIC(arg2)->klass = rb_obj_class(ary);
rb_ary_splice(ary, pos, len, Qundef); /* Qnil/rb_ary_new2(0) */