Skip to content

Commit 11a64a1

Browse files
committed
don't panic in BorrowedCursor::write
1 parent 35e4163 commit 11a64a1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/std/src/io/readbuf.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ impl<'a> BorrowedCursor<'a> {
306306

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

313314
#[inline]

0 commit comments

Comments
 (0)