Skip to content

Commit 37db5e2

Browse files
committed
Simplify Vec allocation in sendmsg after 077d979 removed alignment hacks.
1 parent 3912a20 commit 37db5e2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/sys/socket/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,12 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<'
258258
len += cmsg.len();
259259
capacity += cmsg.space();
260260
}
261-
// Alignment hackery. Note that capacity is guaranteed to be a
262-
// multiple of size_t. Note also that the resulting vector claims
263-
// to have length == capacity, so it's presently uninitialized.
261+
// Note that the resulting vector claims to have length == capacity,
262+
// so it's presently uninitialized.
264263
let mut cmsg_buffer = unsafe {
265264
let mut vec = Vec::<u8>::with_capacity(len);
266-
let ptr = vec.as_mut_ptr();
267-
mem::forget(vec);
268-
Vec::<u8>::from_raw_parts(ptr as *mut _, len, len)
265+
vec.set_len(len);
266+
vec
269267
};
270268
{
271269
let mut ptr = &mut cmsg_buffer[..];

0 commit comments

Comments
 (0)