Skip to content

Commit 96c3d54

Browse files
authored
fix: Fix power of two computation on 32bit architectures (#1624)
The current `compute_previous_power_of_two()` implementation used for TermHashmap takes and returns `usize` , but actually only works correclty on 64 bit architectures (aka usize == u64) On other architectures the leading_zeros computation is run on the wrong type (must be u64), and leads to overflows. Fixed simply computing the leading_zeros based on a u64 value.
1 parent c9cf9c9 commit 96c3d54

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/postings/stacker/term_hashmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a> Iterator for Iter<'a> {
9898
/// # Panics if n == 0
9999
fn compute_previous_power_of_two(n: usize) -> usize {
100100
assert!(n > 0);
101-
let msb = (63u32 - n.leading_zeros()) as u8;
101+
let msb = (63u32 - (n as u64).leading_zeros()) as u8;
102102
1 << msb
103103
}
104104

0 commit comments

Comments
 (0)