From f754b422855131111092c0c147d744775cc4793f Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Fri, 23 Oct 2020 15:26:51 +0900 Subject: numeric.c, range.c: prohibit zero step * numeric.c: prohibit zero step in Numeric#step * range.c: prohibit zero step in Range#step * Fix ruby-spec [Feature #15573] --- numeric.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index fb9b28bcb3..7495b11095 100644 --- a/numeric.c +++ b/numeric.c @@ -2695,9 +2695,9 @@ num_step_check_fix_args(int argc, VALUE *to, VALUE *step, VALUE by, int fix_nil, if (argc > 1 && NIL_P(*step)) { rb_raise(rb_eTypeError, "step must be numeric"); } - if (!allow_zero_step && rb_equal(*step, INT2FIX(0))) { - rb_raise(rb_eArgError, "step can't be 0"); - } + } + if (!allow_zero_step && rb_equal(*step, INT2FIX(0))) { + rb_raise(rb_eArgError, "step can't be 0"); } if (NIL_P(*step)) { *step = INT2FIX(1); @@ -2801,6 +2801,9 @@ num_step(int argc, VALUE *argv, VALUE from) if (NIL_P(step)) { step = INT2FIX(1); } + else if (rb_equal(step, INT2FIX(0))) { + rb_raise(rb_eArgError, "step can't be 0"); + } if ((NIL_P(to) || rb_obj_is_kind_of(to, rb_cNumeric)) && rb_obj_is_kind_of(step, rb_cNumeric)) { return rb_arith_seq_new(from, ID2SYM(rb_frame_this_func()), argc, argv, -- cgit v1.2.3