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 23211b6 commit 2e3ee23Copy full SHA for 2e3ee23
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(|_| Err(Error::INVALID_UTF8))
392
} else {
393
g.len = g.buf.len();
0 commit comments