summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-20 00:10:46 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-20 00:10:46 (GMT)
commitad5a6aa790068a323f9129e92b383c9685700b51 (patch)
treed9c1790847a962c18b30502bd7d1305566573f1c /range.c
parent5a5c9a706c2578a17b95b4afb3c1baaa9e862166 (diff)
range.c: fix fixnum loop condition
* range.c (range_step): FIXABLE + FIXABLE never overflow, but may not be FIXABLE. [Feature #12912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/range.c b/range.c
index fb3a4cb..71d81fa 100644
--- a/range.c
+++ b/range.c
@@ -402,11 +402,10 @@ range_step(int argc, VALUE *argv, VALUE range)
if (FIXNUM_P(b) && NIL_P(e) && FIXNUM_P(step)) {
long i = FIX2LONG(b), unit = FIX2LONG(step);
- while (1) {
+ do {
rb_yield(LONG2FIX(i));
- if (i + unit < i) break;
- i += unit;
- }
+ i += unit; /* FIXABLE+FIXABLE never overflow */
+ } while (FIXABLE(i));
b = LONG2NUM(i);
for (;; b = rb_funcallv(b, id_succ, 0, 0))