Skip to content

Commit 482a913

Browse files
committed
Auto merge of #49315 - TheDan64:smaller_unsafe_block, r=joshtriplett
Reduce scope of unsafe block in sun_path_offset I reduced the scope of the unsafe block to the `uninitialized` call which is the only actual unsafe bit.
2 parents e5bf042 + fdde09c commit 482a913

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/libstd/sys/unix/ext/net.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ use libc::MSG_NOSIGNAL;
5151
const MSG_NOSIGNAL: libc::c_int = 0x0;
5252

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

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

0 commit comments

Comments
 (0)