Simplify Vec allocation in sendmsg after removed alignment hacks.
@@ -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[..];
