Skip to content

Commit

Permalink
Use slice::from_raw_parts instead of mem::transmute
Browse files Browse the repository at this point in the history
Using `mem::transmute` to transmute between slices is UB as far as I
know because slice representation isn't guaranteed.
  • Loading branch information
tbu- committed Jan 16, 2025
1 parent cb4459a commit 1e938f2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ pub fn notify_with_fds(

#[cfg(feature = "fdstore")]
fn borrowed_fd_slice<'a>(s: &'a [BorrowedFd<'_>]) -> &'a [RawFd] {
use std::slice;

// SAFETY: BorrowedFd is #[repr(transparent)] over RawFd (memory safety)
// and implements AsRawFd (lifetime safety).
// Required only because sendfd does not have i/o safety traits.
unsafe { std::mem::transmute(s) }
unsafe { slice::from_raw_parts(s.as_ptr() as *const RawFd, s.len()) }
}

fn connect_notify_socket(unset_env: bool) -> io::Result<Option<UnixDatagram>> {
Expand Down

0 comments on commit 1e938f2

Please sign in to comment.