summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-14 09:18:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-14 09:18:51 +0000
commit7a6542400dfce2ebb260da2c64cbb0e626b1243e (patch)
tree9dd6e0bf740e6081fa18dcf8d5646ed0ad7c685e /array.c
parentb0d53d51f5ce538095ffebaa0e8fd0552b5ebd75 (diff)
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
Diffstat (limited to 'array.c')
-rw-r--r--array.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/array.c b/array.c
index 89b5f98688..96746526e9 100644
--- a/array.c
+++ b/array.c
@@ -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])));