diff options
author | Kenta Murata <mrkn@users.noreply.github.com> | 2020-10-23 15:26:51 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-23 15:26:51 +0900 |
commit | f754b422855131111092c0c147d744775cc4793f (patch) | |
tree | 1ca57f3b6cedb36549c456a79a57cffce940e6fc /range.c | |
parent | 40bad72f31248c48048249b1d7536e87b4994664 (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 'range.c')
-rw-r--r-- | range.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -415,6 +415,13 @@ range_step(int argc, VALUE *argv, VALUE range) step = (!rb_check_arity(argc, 0, 1) ? INT2FIX(1) : argv[0]); if (!rb_block_given_p()) { + if (!rb_obj_is_kind_of(step, rb_cNumeric)) { + step = rb_to_int(step); + } + if (rb_equal(step, INT2FIX(0))) { + rb_raise(rb_eArgError, "step can't be 0"); + } + const VALUE b_num_p = rb_obj_is_kind_of(b, rb_cNumeric); const VALUE e_num_p = rb_obj_is_kind_of(e, rb_cNumeric); if ((b_num_p && (NIL_P(e) || e_num_p)) || (NIL_P(b) && e_num_p)) { |