We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c97f11a commit ebe402dCopy full SHA for ebe402d
library/std/src/io/mod.rs
@@ -390,7 +390,14 @@ where
390
ret = Ok(g.len - start_len);
391
break;
392
}
393
- Ok(n) => g.len += n,
+ Ok(n) => {
394
+ // We can't let g.len overflow which would result in the vec shrinking when the function returns. In
395
+ // particular, that could break read_to_string if the shortened buffer doesn't end on a UTF-8 boundary.
396
+ // The minimal check would just be a checked_add, but this assert is a bit more precise and should be
397
+ // just about the same cost.
398
+ assert!(n <= g.buf.len() - g.len);
399
+ g.len += n;
400
+ }
401
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
402
Err(e) => {
403
ret = Err(e);
0 commit comments