diff --git a/serde/src/de/format.rs b/serde/src/de/format.rs index 58ec0968..f14580b8 100644 --- a/serde/src/de/format.rs +++ b/serde/src/de/format.rs @@ -1,7 +1,7 @@ use lib::fmt::{self, Write}; use lib::str; -pub struct Buf<'a> { +pub(super) struct Buf<'a> { bytes: &'a mut [u8], offset: usize, } diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 8e865558..ccef4d29 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -736,8 +736,9 @@ impl Serialize for net::Ipv4Addr { // Skip over delimiters that we initialized buf with written += format_u8(*oct, &mut buf[written + 1..]) + 1; } - // We've only written ASCII bytes to the buffer, so it is valid UTF-8 - serializer.serialize_str(unsafe { str::from_utf8_unchecked(&buf[..written]) }) + // Safety: We've only written ASCII bytes to the buffer, so it is valid UTF-8 + let buf = unsafe { str::from_utf8_unchecked(&buf[..written]) }; + serializer.serialize_str(buf) } else { self.octets().serialize(serializer) }