Skip to content

Commit 1be0096

Browse files
odaysecrwstauner
authored andcommitted
Fix integer overflow checks in enumerator
1 parent e4dd078 commit 1be0096

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"
@@ -4000,7 +4001,7 @@ arith_seq_take(VALUE self, VALUE num)
40004001
ary = rb_ary_new_capa((n < len) ? n : len);
40014002
while (n > 0 && i < end) {
40024003
rb_ary_push(ary, LONG2FIX(i));
4003-
if (i + unit < i) break;
4004+
if (i > LONG_MAX - unit) break;
40044005
i += unit;
40054006
--n;
40064007
}
@@ -4013,7 +4014,7 @@ arith_seq_take(VALUE self, VALUE num)
40134014
ary = rb_ary_new_capa((n < len) ? n : len);
40144015
while (n > 0 && i > end) {
40154016
rb_ary_push(ary, LONG2FIX(i));
4016-
if (i + unit > i) break;
4017+
if (i < LONG_MIN - unit) break;
40174018
i += unit;
40184019
--n;
40194020
}

0 commit comments

Comments
 (0)