Skip to content

Commit

Permalink
Merge pull request #15 from tbu-/pr_slice_transmute
Browse files Browse the repository at this point in the history
Use `slice::from_raw_parts` instead of `mem::transmute`
  • Loading branch information
lnicola authored Jan 16, 2025
2 parents cb4459a + 1e938f2 commit 6958ce1
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 6958ce1

Please sign in to comment.