Skip to content
This repository was archived by the owner on May 17, 2018. It is now read-only.

Commit 12b30f5

Browse files
committed
Fix UB in offset calculation
1 parent 9aa9fb8 commit 12b30f5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ extern "C" {
2828

2929
fn sun_path_offset() -> usize {
3030
unsafe {
31-
&(*(0 as *const libc::sockaddr_un)).sun_path as *const _ as usize
31+
let addr: libc::sockaddr_un = mem::zeroed();
32+
let base = &addr as *const _ as usize;
33+
let path = &addr.sun_path as *const _ as usize;
34+
path - base
3235
}
3336
}
3437

0 commit comments

Comments
 (0)