diff options
author | Matthew Gregan <kinetik@flim.org> | 2017-06-20 15:26:59 +1200 |
---|---|---|
committer | Matthew Gregan <kinetik@flim.org> | 2017-07-10 13:03:56 +1200 |
commit | 2e00adf804f0ebacfe982063c0f98af836efd4f1 (patch) | |
tree | e7af8e042589c991f3fb488485ad64cdb4195f35 /src | |
parent | 386c50cf0a9c3d5c1e481fb76ee2f17a12b3fc44 (diff) | |
download | nix-2e00adf804f0ebacfe982063c0f98af836efd4f1.zip |
Simplify Vec allocation in sendmsg after 077d979a removed alignment hacks.
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/socket/mod.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index a126f8b4..88fe02fe 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -258,14 +258,12 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<' len += cmsg.len(); capacity += cmsg.space(); } - // Alignment hackery. Note that capacity is guaranteed to be a - // multiple of size_t. Note also that the resulting vector claims - // to have length == capacity, so it's presently uninitialized. + // Note that the resulting vector claims to have length == capacity, + // so it's presently uninitialized. let mut cmsg_buffer = unsafe { let mut vec = Vec::<u8>::with_capacity(len); - let ptr = vec.as_mut_ptr(); - mem::forget(vec); - Vec::<u8>::from_raw_parts(ptr as *mut _, len, len) + vec.set_len(len); + vec }; { let mut ptr = &mut cmsg_buffer[..]; |