aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-05 23:32:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-05 23:32:50 +0000
commit4b4fec4b3a84ae980c25ef38e511784468e908ab (patch)
tree454c368ed3e59dcc7071d7e9079611c9b7610487 /enum.c
parentf4bb41d5cf504831d072bd5349937f03f93d1dd1 (diff)
downloadruby-4b4fec4b3a84ae980c25ef38e511784468e908ab.tar.gz
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/trunk@60668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/enum.c b/enum.c
index 2b2806a6c8..086e3aa13c 100644
--- a/enum.c
+++ b/enum.c
@@ -2840,18 +2840,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;
- if (FIXNUM_ZERO_P(size)) return size;
+ 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);
n = LONG2FIX(mul);
return rb_funcallv(size, '*', 1, &n);