Skip to content

Commit 5d81571

Browse files
committed
Auto merge of #489 - fiveop:fixcopyinto, r=fiveop
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. See #473
2 parents 20d05a1 + 3faaca1 commit 5d81571

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
@@ -229,8 +229,13 @@ impl<'a> ControlMessage<'a> {
229229

230230
let padlen = cmsg_align(mem::size_of_val(&cmsg)) -
231231
mem::size_of_val(&cmsg);
232-
let buf2 = &mut &mut buf[padlen..];
233-
copy_bytes(fds, buf2);
232+
233+
let mut tmpbuf = &mut [][..];
234+
mem::swap(&mut tmpbuf, buf);
235+
let (_padding, mut remainder) = tmpbuf.split_at_mut(padlen);
236+
mem::swap(buf, &mut remainder);
237+
238+
copy_bytes(fds, buf);
234239
},
235240
ControlMessage::Unknown(UnknownCmsg(orig_cmsg, bytes)) => {
236241
copy_bytes(orig_cmsg, buf);

0 commit comments

Comments
 (0)