Skip to content

Commit

Permalink
Reduce scope of unsafe block in sun_path_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDan64 committed Mar 23, 2018
1 parent 55e1104 commit fdde09c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/libstd/sys/unix/ext/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ use libc::MSG_NOSIGNAL;
const MSG_NOSIGNAL: libc::c_int = 0x0;

fn sun_path_offset() -> usize {
unsafe {
// Work with an actual instance of the type since using a null pointer is UB
let addr: libc::sockaddr_un = mem::uninitialized();
let base = &addr as *const _ as usize;
let path = &addr.sun_path as *const _ as usize;
path - base
}
// Work with an actual instance of the type since using a null pointer is UB
let addr: libc::sockaddr_un = unsafe { mem::uninitialized() };
let base = &addr as *const _ as usize;
let path = &addr.sun_path as *const _ as usize;
path - base
}

unsafe fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::socklen_t)> {
Expand Down

0 comments on commit fdde09c

Please sign in to comment.