about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2016-09-27 00:00:00 +0200
committerTomasz Miąsko <tomasz.miasko@gmail.com>2016-09-27 17:55:20 +0200
commit26f9949bf678abc1fae595e3f6eb59a5bf8a7564 (patch)
treee1d7d67bcbd010b73ed6bbfdbc8d2f916af57335 /src/libstd
parent8467e8d24a48027d3d328c6135c0a55cfc9a4cf9 (diff)
downloadrust-26f9949bf678abc1fae595e3f6eb59a5bf8a7564.tar.gz
rust-26f9949bf678abc1fae595e3f6eb59a5bf8a7564.zip
[std::io::Chain] Mark first as done only when reading into non-zero length buffer.
Fixes #36771.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/mod.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 06609cfad15..0de02cbf19c 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -1432,7 +1432,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
     fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
         if !self.done_first {
             match self.first.read(buf)? {
-                0 => { self.done_first = true; }
+                0 if buf.len() != 0 => { self.done_first = true; }
                 n => return Ok(n),
             }
         }
@@ -1959,6 +1959,17 @@ mod tests {
         cmp_bufread(chain1, chain2, &testdata[..]);
     }
 
+    #[test]
+    fn chain_zero_length_read_is_not_eof() {
+        let a = b"A";
+        let b = b"B";
+        let mut s = String::new();
+        let mut chain = (&a[..]).chain(&b[..]);
+        chain.read(&mut []).unwrap();
+        chain.read_to_string(&mut s).unwrap();
+        assert_eq!("AB", s);
+    }
+
     #[bench]
     fn bench_read_to_end(b: &mut test::Bencher) {
         b.iter(|| {