Skip to content

Commit 3185786

Browse files
odaysecnobu
authored andcommitted
Fix integer overflow checks in enumerator
1 parent b61e18d commit 3185786

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

enumerator.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <float.h>
1919
#endif
2020

21+
#include <limits.h>
2122
#include "id.h"
2223
#include "internal.h"
2324
#include "internal/class.h"
@@ -4008,7 +4009,7 @@ arith_seq_take(VALUE self, VALUE num)
40084009
ary = rb_ary_new_capa((n < len) ? n : len);
40094010
while (n > 0 && i < end) {
40104011
rb_ary_push(ary, LONG2FIX(i));
4011-
if (i + unit < i) break;
4012+
if (i > LONG_MAX - unit) break;
40124013
i += unit;
40134014
--n;
40144015
}
@@ -4021,7 +4022,7 @@ arith_seq_take(VALUE self, VALUE num)
40214022
ary = rb_ary_new_capa((n < len) ? n : len);
40224023
while (n > 0 && i > end) {
40234024
rb_ary_push(ary, LONG2FIX(i));
4024-
if (i + unit > i) break;
4025+
if (i < LONG_MIN - unit) break;
40254026
i += unit;
40264027
--n;
40274028
}

0 commit comments

Comments
 (0)