summaryrefslogtreecommitdiff
path: root/src/sys/socket/mod.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2020-04-25 15:39:03 -0600
committerGleb Pomykalov <gleb@lancastr.com>2020-04-26 03:07:09 +0300
commit5decdd74210c961d7cf4dd80a836863097dd5763 (patch)
treeee77d1089f12c5263cf1420814b98d28de049402 /src/sys/socket/mod.rs
parent833369b2413a44ed0477cf8618e4088e523ca137 (diff)
downloadnix-5decdd74210c961d7cf4dd80a836863097dd5763.zip
Eliminate a mem::zeroed() in recvmmsg
Diffstat (limited to 'src/sys/socket/mod.rs')
-rw-r--r--src/sys/socket/mod.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 2d214e7e..9b770fa8 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -982,16 +982,18 @@ pub fn recvmmsg<'a, I>(
let mut output: Vec<libc::mmsghdr> = Vec::with_capacity(num_messages);
- // Addresses should be pre-allocated and never change the address during building
- // of the input data for `recvmmsg`
- let mut addresses: Vec<sockaddr_storage> = vec![unsafe { mem::zeroed() }; num_messages];
+ // Addresses should be pre-allocated. pack_mhdr_to_receive will store them
+ // as raw pointers, so we may not move them. Turn the vec into a boxed
+ // slice so we won't inadvertently reallocate the vec.
+ let mut addresses = vec![mem::MaybeUninit::uninit(); num_messages]
+ .into_boxed_slice();
let results: Vec<_> = iter.enumerate().map(|(i, d)| {
let (msg_controllen, mhdr) = unsafe {
pack_mhdr_to_receive(
d.iov.as_ref(),
&mut d.cmsg_buffer,
- &mut addresses[i],
+ addresses[i].as_mut_ptr(),
)
};
@@ -1017,7 +1019,7 @@ pub fn recvmmsg<'a, I>(
Ok(output
.into_iter()
- .zip(addresses.into_iter())
+ .zip(addresses.iter().map(|addr| unsafe{addr.assume_init()}))
.zip(results.into_iter())
.map(|((mmsghdr, address), (msg_controllen, cmsg_buffer))| {
unsafe {