Skip to content

Commit 15104f9

Browse files
odaysecrwstauner
authored andcommitted
Fix integer overflow checks in enumerator
1 parent 91f0a5a commit 15104f9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎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"
@@ -3963,7 +3964,7 @@ arith_seq_first(int argc, VALUE *argv, VALUE self)
39633964
ary = rb_ary_new_capa((n < len) ? n : len);
39643965
while (n > 0 && i < end) {
39653966
rb_ary_push(ary, LONG2FIX(i));
3966-
if (i + unit < i) break;
3967+
if (i > LONG_MAX - unit) break;
39673968
i += unit;
39683969
--n;
39693970
}
@@ -3976,7 +3977,7 @@ arith_seq_first(int argc, VALUE *argv, VALUE self)
39763977
ary = rb_ary_new_capa((n < len) ? n : len);
39773978
while (n > 0 && i > end) {
39783979
rb_ary_push(ary, LONG2FIX(i));
3979-
if (i + unit > i) break;
3980+
if (i < LONG_MIN - unit) break;
39803981
i += unit;
39813982
--n;
39823983
}

0 commit comments

Comments
 (0)