From 64815c61836ece60d6d01d1a1ecfc1877d5bb866 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Tue, 20 Jun 2017 15:30:48 +1200 Subject: Fix sendmsg on macOS when passing a zero entry cmsgs array. --- src/sys/socket/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 88fe02fe..c11b5367 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -277,12 +277,18 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<' None => (0 as *const _, 0), }; + let cmsg_ptr = if capacity > 0 { + cmsg_buffer.as_ptr() as *const c_void + } else { + ptr::null() + }; + let mhdr = msghdr { msg_name: name as *const c_void, msg_namelen: namelen, msg_iov: iov.as_ptr(), msg_iovlen: iov.len() as size_t, - msg_control: cmsg_buffer.as_ptr() as *const c_void, + msg_control: cmsg_ptr, msg_controllen: capacity as size_t, msg_flags: 0, }; -- cgit v1.2.3