summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorKenta Murata <mrkn@users.noreply.github.com>2020-10-23 15:26:51 +0900
committerGitHub <noreply@github.com>2020-10-23 15:26:51 +0900
commitf754b422855131111092c0c147d744775cc4793f (patch)
tree1ca57f3b6cedb36549c456a79a57cffce940e6fc /numeric.c
parent40bad72f31248c48048249b1d7536e87b4994664 (diff)
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]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3689 Merged-By: mrkn <mrkn@ruby-lang.org>
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c9
1 files changed, 6 insertions, 3 deletions
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,