summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-04-21 13:02:29 +0900
committerGitHub <noreply@github.com>2021-04-21 13:02:29 +0900
commitfb04c69418ceee696a114fe31279cf3a5ea16d30 (patch)
tree0f8d78e40d15172c80ec0853fb37ea755049394c /array.c
parentd427e3cd6f1b39624c9935ade25b4dcb334bee36 (diff)
array.c (rb_ary_zip): take only as many as needed from an Enumerator (#4389)
[Bug #17814]
Notes
Notes: Merged-By: mame <mame@ruby-lang.org>
Diffstat (limited to 'array.c')
-rw-r--r--array.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/array.c b/array.c
index f97be64655..76f11581d2 100644
--- a/array.c
+++ b/array.c
@@ -4311,10 +4311,9 @@ static VALUE
take_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, cbarg))
{
VALUE *args = (VALUE *)cbarg;
- if (args[1] == 0) rb_iter_break();
- else args[1]--;
if (argc > 1) val = rb_ary_new4(argc, argv);
rb_ary_push(args[0], val);
+ if (--args[1] == 0) rb_iter_break();
return Qnil;
}
@@ -4324,6 +4323,7 @@ take_items(VALUE obj, long n)
VALUE result = rb_check_array_type(obj);
VALUE args[2];
+ if (n == 0) return result;
if (!NIL_P(result)) return rb_ary_subseq(result, 0, n);
result = rb_ary_new2(n);
args[0] = result; args[1] = (VALUE)n;