Skip to content

Commit 400a77a

Browse files
committed
Fix sendmsg on macOS when passing a zero entry cmsgs array.
1 parent 78eca21 commit 400a77a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/sys/socket/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,18 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<'
277277
None => (0 as *const _, 0),
278278
};
279279

280+
let cmsg_ptr = if capacity > 0 {
281+
cmsg_buffer.as_ptr() as *const c_void
282+
} else {
283+
ptr::null()
284+
};
285+
280286
let mhdr = msghdr {
281287
msg_name: name as *const c_void,
282288
msg_namelen: namelen,
283289
msg_iov: iov.as_ptr(),
284290
msg_iovlen: iov.len() as size_t,
285-
msg_control: cmsg_buffer.as_ptr() as *const c_void,
291+
msg_control: cmsg_ptr,
286292
msg_controllen: capacity as size_t,
287293
msg_flags: 0,
288294
};

0 commit comments

Comments
 (0)