Skip to content

Commit c544483

Browse files
committed
read_to_end should fit >=MAX_LEN_UTF8 in buf
On Windows, the UTF-16 to UTF-8 translation is made simpler by ensuring we don't split code points.
1 parent a30f178 commit c544483

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library/std/src/io/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(
464464
}
465465
}
466466

467-
if buf.len() == buf.capacity() {
467+
// Ensure there's at least enough space for one UTF-8 encoded code point.
468+
if buf.spare_capacity_mut().len() < char::MAX_LEN_UTF8 {
468469
// buf is full, need more space
469470
buf.try_reserve(PROBE_SIZE)?;
470471
}

0 commit comments

Comments
 (0)