diff --git a/noq-udp/src/cmsg/mod.rs b/noq-udp/src/cmsg/mod.rs index 3e82cbabf7..408f675d52 100644 --- a/noq-udp/src/cmsg/mod.rs +++ b/noq-udp/src/cmsg/mod.rs @@ -41,9 +41,7 @@ impl<'a, M: MsgHdr> Encoder<'a, M> { /// /// # Panics /// - If insufficient buffer space remains. - /// - If `T` has stricter alignment requirements than `M::ControlMessage` pub(crate) fn push(&mut self, level: c_int, ty: c_int, value: T) { - assert!(align_of::() <= align_of::()); let space = M::ControlMessage::cmsg_space(size_of_val(&value)); assert!( self.hdr.control_len() >= self.len + space, @@ -54,7 +52,8 @@ impl<'a, M: MsgHdr> Encoder<'a, M> { let cmsg = self.cmsg.take().expect("no control buffer space remaining"); cmsg.set(level, ty, M::ControlMessage::cmsg_len(size_of_val(&value))); unsafe { - ptr::write(cmsg.cmsg_data() as *const T as *mut T, value); + // Unaligned: `align_of::()` is 4 on musl. + ptr::write_unaligned(cmsg.cmsg_data() as *const T as *mut T, value); } self.len += space; self.cmsg = unsafe { self.hdr.cmsg_nxt_hdr(cmsg).as_mut() }; @@ -78,9 +77,10 @@ impl Drop for Encoder<'_, M> { /// /// `cmsg` must refer to a native cmsg containing a payload of type `T` pub(crate) unsafe fn decode(cmsg: &impl CMsgHdr) -> T { - assert!(align_of::() <= align_of::()); debug_assert_eq!(cmsg.len(), C::cmsg_len(size_of::())); - unsafe { ptr::read(cmsg.cmsg_data() as *const T) } + // Unaligned: `align_of::()` is 4 on musl, but payloads such as + // `libc::timespec` (SCM_TIMESTAMPNS) need 8. + unsafe { ptr::read_unaligned(cmsg.cmsg_data() as *const T) } } pub(crate) struct Iter<'a, M: MsgHdr> {