Skip to content

Commit

Permalink
Fix io::Take::read_buf
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Sep 23, 2024
1 parent 9d6039c commit ba3b536
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,7 @@ impl<T: Read> Read for Take<T> {
}

let mut cursor = sliced_buf.unfilled();
self.inner.read_buf(cursor.reborrow())?;
let result = self.inner.read_buf(cursor.reborrow());

let new_init = cursor.init_ref().len();
let filled = sliced_buf.len();
Expand All @@ -2956,13 +2956,14 @@ impl<T: Read> Read for Take<T> {
}

self.limit -= filled as u64;

result
} else {
let written = buf.written();
self.inner.read_buf(buf.reborrow())?;
let result = self.inner.read_buf(buf.reborrow());
self.limit -= (buf.written() - written) as u64;
result
}

Ok(())
}
}

Expand Down

0 comments on commit ba3b536

Please sign in to comment.