|
let entry = unsafe { *self.table.get_unchecked((hash as usize) & self.mask) }; |
|
let e = unsafe { self.table.get_unchecked_mut((hash as usize) & self.mask) }; |
|
let e = unsafe { self.table.get_unchecked_mut((hash as usize) & self.mask) }; |
On 32-bit systems
hash as usize will overflow if the value of
hash is greater than
u32::MAX.
This overflow is mostly harmless in release mode (as the hash will just be truncated to the 32-bit boundary), but it will cause a panic in debug mode.
Replace (hash as usize) & self.mask with (hash & (self.mask as u64)) as usize to prevent overflow.
You may also want to change the type of self.mask to u64
chess/src/cache_table.rs
Line 39 in 0e538fb
chess/src/cache_table.rs
Line 50 in 0e538fb
chess/src/cache_table.rs
Line 83 in 0e538fb
On 32-bit systems
hash as usizewill overflow if the value ofhashis greater thanu32::MAX.This overflow is mostly harmless in release mode (as the hash will just be truncated to the 32-bit boundary), but it will cause a panic in debug mode.
Replace
(hash as usize) & self.maskwith(hash & (self.mask as u64)) as usizeto prevent overflow.You may also want to change the type of
self.masktou64