diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-16 16:41:23 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-16 16:41:23 +0000 |
commit | fc4bb0da3ba302ae7c0da3f529f59a721b888d28 (patch) | |
tree | cc5ee90659c4efef8f0fc8a15babe68b6a8e88de /enum.c | |
parent | 12fc812978a0d2cfbf4a40e392231303344ae68e (diff) |
merge revision(s) 60666,60667,60668: [Backport #14082]
Fix size on Enumerable#cycle when the size is 0 [Bug #14082].
Patch by Kenichi Kamiya
test/ruby/test_lazy_enumerator.rb: test for [Bug #14082]
enum.c: check argument first
* enum.c (enum_cycle_size): check an argument before the size of
the receiver, if it is given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -2810,17 +2810,19 @@ cycle_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ary)) static VALUE enum_cycle_size(VALUE self, VALUE args, VALUE eobj) { - long mul; + long mul = 0; VALUE n = Qnil; - VALUE size = enum_size(self, args, 0); - - if (size == Qnil) return Qnil; + VALUE size; if (args && (RARRAY_LEN(args) > 0)) { n = RARRAY_AREF(args, 0); + if (!NIL_P(n)) mul = NUM2LONG(n); } - if (n == Qnil) return DBL2NUM(INFINITY); - mul = NUM2LONG(n); + + size = enum_size(self, args, 0); + if (NIL_P(size) || FIXNUM_ZERO_P(size)) return size; + + if (NIL_P(n)) return DBL2NUM(INFINITY); if (mul <= 0) return INT2FIX(0); return rb_funcall(size, '*', 1, LONG2FIX(mul)); } |