From: Satoshi Nakagawa Date: 2007-08-29T03:58:21+09:00 Subject: [ruby-dev:31671] Array#slice! --Apple-Mail-4--433111398 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP 中川といいます。 Array#slice! に、配列のサイズを超える負の値を渡したときの 挙動がおかしいと思います。 trunk と 1.8 の最新版で再現しました。 $ ./ruby -v ruby 1.8.6 (2007-08-28 patchlevel 5000) [i686-darwin8.10.1] $ ./ruby -e 'a=[1,2,3,4,5];a.slice!(-3,1);p a' [1, 2, 4, 5] $ ./ruby -e 'a=[1,2,3,4,5];a.slice!(-8,1);p a' [1, 2, 4, 5] 添付のパッチをあてると直りました。 $ ./ruby -e 'a=[1,2,3,4,5];a.slice!(-3,1);p a' [1, 2, 4, 5] $ ./ruby -e 'a=[1,2,3,4,5];a.slice!(-8,1);p a' -e:1:in `slice!': index -8 out of array (IndexError) from -e:1 -- Satoshi Nakagawa http://d.hatena.ne.jp/Psychs/ --Apple-Mail-4--433111398 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name=ruby18_slice_bang.patch Content-Disposition: attachment; filename=ruby18_slice_bang.patch Index: array.c =================================================================== --- array.c (revision 13297) +++ array.c (working copy) @@ -1961,9 +1961,6 @@ pos = NUM2LONG(arg1); len = NUM2LONG(arg2); delete_pos_len: - if (pos < 0) { - pos = RARRAY(ary)->len + pos; - } arg2 = rb_ary_subseq(ary, pos, len); rb_ary_splice(ary, pos, len, Qnil); /* Qnil/rb_ary_new2(0) */ return arg2; --Apple-Mail-4--433111398 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name=ruby19_slice_bang.patch Content-Disposition: attachment; filename=ruby19_slice_bang.patch Index: array.c =================================================================== --- array.c (revision 13297) +++ array.c (working copy) @@ -1893,9 +1893,6 @@ pos = NUM2LONG(arg1); len = NUM2LONG(arg2); delete_pos_len: - if (pos < 0) { - pos = RARRAY_LEN(ary) + pos; - } arg2 = rb_ary_subseq(ary, pos, len); rb_ary_splice(ary, pos, len, Qundef); /* Qnil/rb_ary_new2(0) */ return arg2; --Apple-Mail-4--433111398 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII --Apple-Mail-4--433111398--