Avoid panicking branch in append_to_string
This commit is contained in:
parent
23211b638a
commit
2e3ee23022
1 changed files with 4 additions and 1 deletions
|
@ -384,7 +384,10 @@ where
|
|||
{
|
||||
let mut g = Guard { len: buf.len(), buf: buf.as_mut_vec() };
|
||||
let ret = f(g.buf);
|
||||
if str::from_utf8(&g.buf[g.len..]).is_err() {
|
||||
|
||||
// SAFETY: the caller promises to only append data to `buf`
|
||||
let appended = g.buf.get_unchecked(g.len..);
|
||||
if str::from_utf8(appended).is_err() {
|
||||
ret.and_then(|_| Err(Error::INVALID_UTF8))
|
||||
} else {
|
||||
g.len = g.buf.len();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue