mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #3472 from qingshi163/fix-slice-overflow
fix #3468 SaturatedSliceIter overflow
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user