Skip to content

Commit 4f79716

Browse files
authored
Auto merge of #36777 - tmiasko:chain-read-eof, r=alexcrichton
[std::io::Chain] Mark first as done only when reading into non-zero length buffer. Fixes #36771.
2 parents d75c84a + 26f9949 commit 4f79716

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/libstd/io/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
14321432
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
14331433
if !self.done_first {
14341434
match self.first.read(buf)? {
1435-
0 => { self.done_first = true; }
1435+
0 if buf.len() != 0 => { self.done_first = true; }
14361436
n => return Ok(n),
14371437
}
14381438
}
@@ -1959,6 +1959,17 @@ mod tests {
19591959
cmp_bufread(chain1, chain2, &testdata[..]);
19601960
}
19611961

1962+
#[test]
1963+
fn chain_zero_length_read_is_not_eof() {
1964+
let a = b"A";
1965+
let b = b"B";
1966+
let mut s = String::new();
1967+
let mut chain = (&a[..]).chain(&b[..]);
1968+
chain.read(&mut []).unwrap();
1969+
chain.read_to_string(&mut s).unwrap();
1970+
assert_eq!("AB", s);
1971+
}
1972+
19621973
#[bench]
19631974
fn bench_read_to_end(b: &mut test::Bencher) {
19641975
b.iter(|| {

0 commit comments

Comments
 (0)