Skip to content

Commit 06d581d

Browse files
committed
Fix #1546 - large ranges.
Raise an error for very large ranges instead of internal assert.
1 parent 2b49903 commit 06d581d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/core/corelib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ JANET_CORE_FN(janet_core_range,
449449
}
450450
count = (count > 0) ? count : 0;
451451
int32_t int_count;
452+
janet_assert(count >= 0, "bad range code");
452453
if (count > (double) INT32_MAX) {
453-
int_count = INT32_MAX;
454+
janet_panicf("range is too large, %f elements", count);
454455
} else {
455456
int_count = (int32_t) ceil(count);
456457
}

test/suite-corelib.janet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
(assert (deep= (range 0 17 4) @[0 4 8 12 16]) "(range 0 17 4)")
175175
(assert (deep= (range 16 0 -4) @[16 12 8 4]) "(range 16 0 -4)")
176176
(assert (deep= (range 17 0 -4) @[17 13 9 5 1]) "(range 17 0 -4)")
177+
(assert-error "large range" (range 0xFFFFFFFFFF))
177178

178179
(assert (= (length (range 10)) 10) "(range 10)")
179180
(assert (= (length (range -10)) 0) "(range -10)")

0 commit comments

Comments
 (0)