Skip to content

Commit 4114e90

Browse files
committed
Fix off-by-one mistake, explain the offset
1 parent 8bb07b0 commit 4114e90

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎serde/src/ser/impls.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ impl Serialize for net::Ipv4Addr {
725725
let mut buf = [b'.'; MAX_LEN];
726726
let mut written = format_u8(self.octets()[0], &mut buf);
727727
for oct in &self.octets()[1..] {
728-
written += format_u8(*oct, &mut buf[written..]) + 1;
728+
// Skip over delimiters that we initialized buf with
729+
written += format_u8(*oct, &mut buf[written + 1..]) + 1;
729730
}
730731
// We've only written ASCII bytes to the buffer, so it is valid UTF-8
731732
serializer.serialize_str(unsafe { str::from_utf8_unchecked(&buf[..written]) })

0 commit comments

Comments
 (0)