Skip to content

Commit 2eef2e2

Browse files
sfacklerMark-Simulacrum
authored andcommitted
clarify docs a bit
1 parent e73125e commit 2eef2e2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

library/std/src/io/mod.rs

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

0 commit comments

Comments
 (0)