Skip to content

Commit

Permalink
fix a potential crash in primes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 10, 2024
1 parent 3994c1d commit f1c88fd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/algorithm/monadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,10 +1432,16 @@ impl Array<f64> {
}
max = max.max(n as usize);
}
if max.overflowing_mul(max).1 {
return Err(env.error(format!(
"Cannot get primes of {} because it is too large",
max
)));
}
validate_size::<usize>([max, 2], env)?;

// Sieve of Eratosthenes
let mut spf = vec![0; max + 1];
let mut spf = vec![1; max + 1];
for i in 2..=max {
spf[i] = i;
}
Expand Down

0 comments on commit f1c88fd

Please sign in to comment.