Skip to content

Commit f0e9a6e

Browse files
committed
Add hard coded guard in loop
1 parent 20d599c commit f0e9a6e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/check.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub const fn is_prime(n: u64) -> bool {
4545
// in order to make the test both fast and deterministic.
4646
// This list of witnesses was taken from
4747
// <https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Testing_against_small_sets_of_bases>.
48-
const WITNESSES: [(u64, &[u64]); 11] = [
48+
const NUM_BASES: usize = 11;
49+
const WITNESSES: [(u64, &[u64]); NUM_BASES] = [
4950
(2_046, &[2]),
5051
(1_373_652, &[2, 3]),
5152
(9_080_190, &[31, 73]),
@@ -61,7 +62,7 @@ pub const fn is_prime(n: u64) -> bool {
6162

6263
// Find the smallest basis that is large enough.
6364
let mut i = 0;
64-
while WITNESSES[i].0 < n {
65+
while WITNESSES[i].0 < n && i < NUM_BASES {
6566
i += 1;
6667
}
6768
let witnesses = WITNESSES[i].1;

0 commit comments

Comments
 (0)