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.
This commit is contained in:
commit
4f7971682f
@ -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(|| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user