From 3faaca1ad2847ffb15fd7f42f63e10b3d85602fc Mon Sep 17 00:00:00 2001 From: Philipp Matthias Schaefer Date: Sat, 10 Dec 2016 21:29:50 +0100 Subject: [PATCH] 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. --- src/sys/socket/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index e041e6b60497a..26f0739dda488 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -238,8 +238,13 @@ impl<'a> ControlMessage<'a> { let padlen = cmsg_align(mem::size_of_val(&cmsg)) - mem::size_of_val(&cmsg); - let buf2 = &mut &mut buf[padlen..]; - copy_bytes(fds, buf2); + + let mut tmpbuf = &mut [][..]; + mem::swap(&mut tmpbuf, buf); + let (_padding, mut remainder) = tmpbuf.split_at_mut(padlen); + mem::swap(buf, &mut remainder); + + copy_bytes(fds, buf); }, ControlMessage::Unknown(UnknownCmsg(orig_cmsg, bytes)) => { copy_bytes(orig_cmsg, buf);