Fix infinite loop in BufReader::read_until.
This commit is contained in:
parent
e9c539a488
commit
71c88e7f47
|
@ -312,7 +312,11 @@ impl<'a> Seek for BufReader<'a> {
|
|||
|
||||
impl<'a> Buffer for BufReader<'a> {
|
||||
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; }
|
||||
}
|
||||
|
@ -449,6 +453,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 = BufReader::new(in_buf);
|
||||
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