1
Fork 0

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.)
This commit is contained in:
Felix S. Klock II 2015-02-20 09:22:40 +01:00
parent 6189e99c86
commit f0404c39f2

View file

@ -1130,7 +1130,11 @@ impl<I> RandomAccessIterator for Rev<I> where I: DoubleEndedIterator + RandomAcc
#[inline]
fn idx(&mut self, index: usize) -> Option<<I as Iterator>::Item> {
let amt = self.indexable();
self.iter.idx(amt - index - 1)
if amt > index {
self.iter.idx(amt - index - 1)
} else {
None
}
}
}