Skip to content

Commit

Permalink
Auto merge of #489 - fiveop:fixcopyinto, r=fiveop
Browse files Browse the repository at this point in the history
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
  • Loading branch information
homu committed Jan 11, 2017
2 parents 20d05a1 + 3faaca1 commit 5d81571
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,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);
Expand Down

0 comments on commit 5d81571

Please sign in to comment.