mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
fix panic in log_base2 in malformed demos
This commit is contained in:
parent
e77770c780
commit
e412399309
1 changed files with 3 additions and 1 deletions
|
|
@ -286,5 +286,7 @@ pub fn read_var_int(stream: &mut Stream) -> ReadResult<u32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_base2<T: PrimInt + Unsigned>(num: T) -> u32 {
|
pub fn log_base2<T: PrimInt + Unsigned>(num: T) -> u32 {
|
||||||
(std::mem::size_of::<T>() as u32 * 8 - 1) - num.leading_zeros()
|
// log(0) = inf, but that's a useless result
|
||||||
|
// since this would only happen in malformed demos, we just return 0
|
||||||
|
(std::mem::size_of::<T>() as u32 * 8 - 1).saturating_sub(num.leading_zeros())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue