std: Fix bug in ChunkIter::idx

ChunkIter .idx() didn't handle overflow correctly, even though it tried.
This commit is contained in:
blake2-ppc
2013-08-04 22:46:26 +02:00
parent ea9c5c405e
commit 45085b9f8d

View File

@@ -547,7 +547,10 @@ impl<'self, T> RandomAccessIterator<&'self [T]> for ChunkIter<'self, T> {
fn idx(&self, index: uint) -> Option<&'self [T]> { fn idx(&self, index: uint) -> Option<&'self [T]> {
if index < self.indexable() { if index < self.indexable() {
let lo = index * self.size; let lo = index * self.size;
Some(self.v.slice(lo, cmp::min(lo, self.v.len() - self.size) + self.size)) let mut hi = lo + self.size;
if hi < lo || hi > self.v.len() { hi = self.v.len(); }
Some(self.v.slice(lo, hi))
} else { } else {
None None
} }