diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-02-20 09:22:40 +0100 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-03-03 12:10:57 +0100 |
| commit | f0404c39f272868c1dedc7cda7b0b6dffcb5713d (patch) | |
| tree | f13c0963de7b154826dde3fc306c37bc0429dbea | |
| parent | 6189e99c8605578aae841be6fba9e27bfbad97fc (diff) | |
| download | rust-f0404c39f272868c1dedc7cda7b0b6dffcb5713d.tar.gz rust-f0404c39f272868c1dedc7cda7b0b6dffcb5713d.zip | |
`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.)
| -rw-r--r-- | src/libcore/iter.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index edc67fbf8c9..55bd7c17245 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -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 + } } } |
