Skip to content

Commit 3faaca1

Browse files
committed
Fix ControlMessage::encode_into when encoding multiple messages
copy_bytes updates dst so that it points after the bytes that were just copied into it. encode_into did not advance the buffer in the same way when encoding the data.
1 parent 2cfeb57 commit 3faaca1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/sys/socket/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,13 @@ impl<'a> ControlMessage<'a> {
238238

239239
let padlen = cmsg_align(mem::size_of_val(&cmsg)) -
240240
mem::size_of_val(&cmsg);
241-
let buf2 = &mut &mut buf[padlen..];
242-
copy_bytes(fds, buf2);
241+
242+
let mut tmpbuf = &mut [][..];
243+
mem::swap(&mut tmpbuf, buf);
244+
let (_padding, mut remainder) = tmpbuf.split_at_mut(padlen);
245+
mem::swap(buf, &mut remainder);
246+
247+
copy_bytes(fds, buf);
243248
},
244249
ControlMessage::Unknown(UnknownCmsg(orig_cmsg, bytes)) => {
245250
copy_bytes(orig_cmsg, buf);

0 commit comments

Comments
 (0)