From 11a64a18342865b166d2da703a06deb447f834c1 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Fri, 1 Sep 2023 20:20:29 -0500 Subject: [PATCH] don't panic in BorrowedCursor::write --- library/std/src/io/readbuf.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/readbuf.rs b/library/std/src/io/readbuf.rs index 034ddd8df9aed..95044de2a09e1 100644 --- a/library/std/src/io/readbuf.rs +++ b/library/std/src/io/readbuf.rs @@ -306,8 +306,9 @@ impl<'a> BorrowedCursor<'a> { impl<'a> Write for BorrowedCursor<'a> { fn write(&mut self, buf: &[u8]) -> Result { - self.append(buf); - Ok(buf.len()) + let amt = cmp::min(buf.len(), self.capacity()); + self.append(&buf[..amt]); + Ok(amt) } #[inline]