Skip to content

Commit febd55a

Browse files
kouhe3dtolnay
andcommitted
use offset_of
Co-authored-by: David Tolnay <dtolnay@gmail.com>
1 parent d069ed4 commit febd55a

File tree

1 file changed

+1
-4
lines changed
  • library/std/src/os/windows/net

1 file changed

+1
-4
lines changed

library/std/src/os/windows/net/addr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ pub fn sockaddr_un(path: &Path) -> io::Result<(c::sockaddr_un, c_int)> {
4141
Ok((addr, len as _))
4242
}
4343
fn sun_path_offset(addr: &c::sockaddr_un) -> usize {
44-
// Work with an actual instance of the type since using a null pointer is UB
45-
let base = addr as *const _ as usize;
46-
let path = &addr.sun_path as *const _ as usize;
47-
path - base
44+
offset_of!(c::sockaddr_un, sun_path)
4845
}
4946
#[allow(dead_code)]
5047
pub struct SocketAddr {

0 commit comments

Comments
 (0)