diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-14 09:18:51 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-14 09:18:51 +0000 |
commit | 7a6542400dfce2ebb260da2c64cbb0e626b1243e (patch) | |
tree | 9dd6e0bf740e6081fa18dcf8d5646ed0ad7c685e | |
parent | b0d53d51f5ce538095ffebaa0e8fd0552b5ebd75 (diff) | |
download | ruby-7a6542400dfce2ebb260da2c64cbb0e626b1243e.tar.gz |
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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | array.c | 14 | ||||
-rw-r--r-- | test/ruby/test_array.rb | 4 |
3 files changed, 14 insertions, 9 deletions
@@ -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] @@ -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]))); diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index a4fda99474..92c624b57b 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -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 |