1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

array.c: fill with nil

* array.c (rb_get_values_at): fill with nil out of range.
  [ruby-core:43678] [Bug #6203]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-07-14 09:18:51 +00:00
parent b0d53d51f5
commit 7a6542400d
3 changed files with 14 additions and 9 deletions

View file

@ -1,3 +1,8 @@
Sat Jul 14 18:18:48 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_get_values_at): fill with nil out of range.
[ruby-core:43678] [Bug #6203]
Sat Jul 14 17:17:55 2012 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
* cont.c (cont_restore_0): improve docs. [Bug #6706][ruby-core:46243]

14
array.c
View file

@ -2362,15 +2362,13 @@ rb_get_values_at(VALUE obj, long olen, int argc, VALUE *argv, VALUE (*func) (VAL
continue;
}
/* check if idx is Range */
switch (rb_range_beg_len(argv[i], &beg, &len, olen, 0)) {
case Qfalse:
break;
case Qnil:
continue;
default:
for (j=0; j<len; j++) {
rb_ary_push(result, (*func)(obj, j+beg));
if (rb_range_beg_len(argv[i], &beg, &len, olen, 1)) {
long end = olen < beg+len ? olen : beg+len;
for (j = beg; j < end; j++) {
rb_ary_push(result, (*func)(obj, j));
}
if (beg + len > j)
rb_ary_resize(result, RARRAY_LEN(result) + (beg + len) - j);
continue;
}
rb_ary_push(result, (*func)(obj, NUM2LONG(argv[i])));

View file

@ -1831,7 +1831,9 @@ class TestArray < Test::Unit::TestCase
def test_values_at2
a = [0, 1, 2, 3, 4, 5]
assert_equal([1, 2, 3], a.values_at(1..3))
assert_equal([], a.values_at(7..8))
assert_equal([nil, nil], a.values_at(7..8))
bug6203 = '[ruby-core:43678]'
assert_equal([4, 5, nil, nil], a.values_at(4..7), bug6203)
assert_equal([nil], a.values_at(2**31-1))
end