Skip to content

Commit f0404c3

Browse files
committed
core::iter: fix bug uncovered by arith-overflow.
(The bug was in `impl RandomAccessIterator for Rev`; it may or may not have been innocuous, depending on what guarantees one has about the behavior of `idx` for the underlying iterator.)
1 parent 6189e99 commit f0404c3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libcore/iter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,11 @@ impl<I> RandomAccessIterator for Rev<I> where I: DoubleEndedIterator + RandomAcc
11301130
#[inline]
11311131
fn idx(&mut self, index: usize) -> Option<<I as Iterator>::Item> {
11321132
let amt = self.indexable();
1133-
self.iter.idx(amt - index - 1)
1133+
if amt > index {
1134+
self.iter.idx(amt - index - 1)
1135+
} else {
1136+
None
1137+
}
11341138
}
11351139
}
11361140

0 commit comments

Comments
 (0)