fix SaturatedSliceIter overflow
@@ -368,13 +368,15 @@ impl SaturatedSliceIter {
impl Iterator for SaturatedSliceIter {
type Item = usize;
+
fn next(&mut self) -> Option<Self::Item> {
if self.len == 0 {
return None;
}
self.len -= 1;
let ret = self.index as usize;
- self.index += self.step;
+ // SAFETY: if index is overflowed, len should be zero
+ self.index = self.index.wrapping_add(self.step);
Some(ret)
}
}
