Skip to content

Commit

Permalink
Fix #1546 - large ranges.
Browse files Browse the repository at this point in the history
Raise an error for very large ranges instead of internal assert.
  • Loading branch information
bakpakin committed Jan 20, 2025
1 parent 2b49903 commit 06d581d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/corelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,9 @@ JANET_CORE_FN(janet_core_range,
}
count = (count > 0) ? count : 0;
int32_t int_count;
janet_assert(count >= 0, "bad range code");
if (count > (double) INT32_MAX) {
int_count = INT32_MAX;
janet_panicf("range is too large, %f elements", count);
} else {
int_count = (int32_t) ceil(count);
}
Expand Down
1 change: 1 addition & 0 deletions test/suite-corelib.janet
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
(assert (deep= (range 0 17 4) @[0 4 8 12 16]) "(range 0 17 4)")
(assert (deep= (range 16 0 -4) @[16 12 8 4]) "(range 16 0 -4)")
(assert (deep= (range 17 0 -4) @[17 13 9 5 1]) "(range 17 0 -4)")
(assert-error "large range" (range 0xFFFFFFFFFF))

(assert (= (length (range 10)) 10) "(range 10)")
(assert (= (length (range -10)) 0) "(range -10)")
Expand Down

0 comments on commit 06d581d

Please sign in to comment.