Skip to content

Commit

Permalink
assert MsgHdr::with_control with empty buffer which causes error in m…
Browse files Browse the repository at this point in the history
…acOS
  • Loading branch information
youknowone committed Apr 22, 2024
1 parent 6923954 commit 0dd6435
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
/// Corresponds to setting `msg_control` and `msg_controllen` on Unix and
/// `Control` on Windows.
pub fn with_control(mut self, buf: &'control [u8]) -> Self {
let ptr = buf.as_ptr() as *mut _;
sys::set_msghdr_control(&mut self.inner, ptr, buf.len());
debug_assert!(!buf.is_empty(), "Empty control buffer might be a programming error");
sys::set_msghdr_control(&mut self.inner, buf.as_ptr() as *mut _, buf.len());
self
}

Expand Down
4 changes: 3 additions & 1 deletion tests/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ fn sendmsg() {

let bufs = &[IoSlice::new(DATA)];
let addr_b = socket_b.local_addr().unwrap();
let msg = socket2::MsgHdr::new().with_addr(&addr_b).with_buffers(bufs);
let msg = socket2::MsgHdr::new()
.with_addr(&addr_b)
.with_buffers(bufs);
let sent = socket_a.sendmsg(&msg, 0).unwrap();
assert_eq!(sent, DATA.len());

Expand Down

0 comments on commit 0dd6435

Please sign in to comment.