Skip to content

Commit

Permalink
don't panic in BorrowedCursor::write
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 committed Sep 2, 2023
1 parent 35e4163 commit 11a64a1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/std/src/io/readbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ impl<'a> BorrowedCursor<'a> {

impl<'a> Write for BorrowedCursor<'a> {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
self.append(buf);
Ok(buf.len())
let amt = cmp::min(buf.len(), self.capacity());
self.append(&buf[..amt]);
Ok(amt)
}

#[inline]
Expand Down

0 comments on commit 11a64a1

Please sign in to comment.