Fix KeySetIter panic when only leading bit is set

This commit is contained in:
Zac Wilson 2025-12-22 17:36:05 +00:00
parent 95d5a18e99
commit fcd4fbadbc

View file

@ -108,13 +108,14 @@ impl core::iter::Iterator for KeySetIter {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
let next_shift = self.key_set.0.trailing_zeros() as u8 + 1;
let next_shift = self.key_set.0.trailing_zeros() as u8;
if next_shift >= 128 {
return None;
}
self.key_set.0 >>= next_shift;
self.shift += next_shift;
self.key_set.0 >>= 1;
self.shift += next_shift + 1;
Some(self.shift - 1)
}