Skip to content

Commit e6c07b0

Browse files
committed
clarify docs a bit
1 parent 5cb8303 commit e6c07b0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

library/std/src/io/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,9 @@ where
388388
match r.read(buf) {
389389
Ok(0) => return Ok(g.len - start_len),
390390
Ok(n) => {
391-
// We can't let g.len overflow which would result in the vec shrinking when the function returns. In
392-
// particular, that could break read_to_string if the shortened buffer doesn't end on a UTF-8 boundary.
393-
// The minimal check would just be a checked_add, but this assert is a bit more precise and should be
394-
// just about the same cost.
391+
// We can't allow bogus values from read. If it is too large, the returned vec could have its length
392+
// set past its capacity, or if it overflows the vec could be shortened which could create an invalid
393+
// string if this is called via read_to_string.
395394
assert!(n <= buf.len());
396395
g.len += n;
397396
}

0 commit comments

Comments
 (0)