We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
append_to_string
1 parent 4db1e83 commit d1d142bCopy full SHA for d1d142b
library/std/src/io/mod.rs
@@ -384,7 +384,10 @@ where
384
{
385
let mut g = Guard { len: buf.len(), buf: buf.as_mut_vec() };
386
let ret = f(g.buf);
387
- if str::from_utf8(&g.buf[g.len..]).is_err() {
+
388
+ // SAFETY: the caller promises to only append data to `buf`
389
+ let appended = g.buf.get_unchecked(g.len..);
390
+ if str::from_utf8(appended).is_err() {
391
ret.and_then(|_| {
392
Err(error::const_io_error!(
393
ErrorKind::InvalidData,
0 commit comments