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:
parent
b0d53d51f5
commit
7a6542400d
@ -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>
|
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]
|
* cont.c (cont_restore_0): improve docs. [Bug #6706][ruby-core:46243]
|
||||||
|
14
array.c
14
array.c
@ -2362,15 +2362,13 @@ rb_get_values_at(VALUE obj, long olen, int argc, VALUE *argv, VALUE (*func) (VAL
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* check if idx is Range */
|
/* check if idx is Range */
|
||||||
switch (rb_range_beg_len(argv[i], &beg, &len, olen, 0)) {
|
if (rb_range_beg_len(argv[i], &beg, &len, olen, 1)) {
|
||||||
case Qfalse:
|
long end = olen < beg+len ? olen : beg+len;
|
||||||
break;
|
for (j = beg; j < end; j++) {
|
||||||
case Qnil:
|
rb_ary_push(result, (*func)(obj, j));
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
for (j=0; j<len; j++) {
|
|
||||||
rb_ary_push(result, (*func)(obj, j+beg));
|
|
||||||
}
|
}
|
||||||
|
if (beg + len > j)
|
||||||
|
rb_ary_resize(result, RARRAY_LEN(result) + (beg + len) - j);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
rb_ary_push(result, (*func)(obj, NUM2LONG(argv[i])));
|
rb_ary_push(result, (*func)(obj, NUM2LONG(argv[i])));
|
||||||
|
@ -1831,7 +1831,9 @@ class TestArray < Test::Unit::TestCase
|
|||||||
def test_values_at2
|
def test_values_at2
|
||||||
a = [0, 1, 2, 3, 4, 5]
|
a = [0, 1, 2, 3, 4, 5]
|
||||||
assert_equal([1, 2, 3], a.values_at(1..3))
|
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))
|
assert_equal([nil], a.values_at(2**31-1))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user