diff options
| author | Tobias Müller <troplin@bluewin.ch> | 2016-04-09 14:23:11 +0200 |
|---|---|---|
| committer | Tobias Müller <troplin@bluewin.ch> | 2016-04-09 14:23:11 +0200 |
| commit | a3329f5452b20fd611537e7db1a86a9fe115008a (patch) | |
| tree | 2af487c8f26d89f69dc4aa861c1c6c95edca6c4d /src/libstd | |
| parent | 7e996943784dcbabed433b6906510298ad80903b (diff) | |
| download | rust-a3329f5452b20fd611537e7db1a86a9fe115008a.tar.gz rust-a3329f5452b20fd611537e7db1a86a9fe115008a.zip | |
Don't read past limit for in BufRead instance of Take
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/mod.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index bcce8ee6abf..e6db558c8c4 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1505,6 +1505,11 @@ impl<T: Read> Read for Take<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: BufRead> BufRead for Take<T> { fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block + if self.limit == 0 { + return Ok(&[]); + } + let buf = self.inner.fill_buf()?; let cap = cmp::min(buf.len() as u64, self.limit) as usize; Ok(&buf[..cap]) @@ -1860,9 +1865,16 @@ mod tests { Err(io::Error::new(io::ErrorKind::Other, "")) } } + impl BufRead for R { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + Err(io::Error::new(io::ErrorKind::Other, "")) + } + fn consume(&mut self, _amt: usize) { } + } let mut buf = [0; 1]; assert_eq!(0, R.take(0).read(&mut buf).unwrap()); + assert_eq!(b"", R.take(0).fill_buf().unwrap()); } fn cmp_bufread<Br1: BufRead, Br2: BufRead>(mut br1: Br1, mut br2: Br2, exp: &[u8]) { |
