mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Fix infinite loop in MemReader::read_until.
This commit is contained in:
parent
a2290db797
commit
e9c539a488
@ -177,7 +177,11 @@ impl Seek for MemReader {
|
||||
|
||||
impl Buffer for MemReader {
|
||||
fn fill<'a>(&'a mut self) -> IoResult<&'a [u8]> {
|
||||
Ok(self.buf.slice_from(self.pos))
|
||||
if self.pos < self.buf.len() {
|
||||
Ok(self.buf.slice_from(self.pos))
|
||||
} else {
|
||||
Err(io::standard_error(io::EndOfFile))
|
||||
}
|
||||
}
|
||||
fn consume(&mut self, amt: uint) { self.pos += amt; }
|
||||
}
|
||||
@ -421,6 +425,10 @@ mod test {
|
||||
assert_eq!(reader.read(buf), Ok(3));
|
||||
assert_eq!(buf.slice(0, 3), [5, 6, 7]);
|
||||
assert!(reader.read(buf).is_err());
|
||||
let mut reader = MemReader::new(~[0, 1, 2, 3, 4, 5, 6, 7]);
|
||||
assert_eq!(reader.read_until(3).unwrap(), ~[0, 1, 2, 3]);
|
||||
assert_eq!(reader.read_until(3).unwrap(), ~[4, 5, 6, 7]);
|
||||
assert!(reader.read(buf).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user