summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2019-08-19 16:19:24 -0600
committerAlan Somers <asomers@gmail.com>2019-08-29 10:06:03 -0600
commit9e360145be630275a9b8a73dc32462ef406d20f6 (patch)
tree6196ac2efc228b90887241ec45e187373538a693
parent417e91363a25c663ff884f3dcb879832bf0a66ed (diff)
downloadnix-9e360145be630275a9b8a73dc32462ef406d20f6.zip
Clippy: remove unnecessary mem::transmute
-rw-r--r--src/sys/socket/addr.rs46
-rw-r--r--src/sys/socket/mod.rs20
2 files changed, 51 insertions, 15 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 1c6f1b54..cbec71f7 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -768,26 +768,54 @@ impl SockAddr {
/// a sockaddr * need to take the size of the underlying type as well and then internally cast it back.
pub unsafe fn as_ffi_pair(&self) -> (&libc::sockaddr, libc::socklen_t) {
match *self {
- SockAddr::Inet(InetAddr::V4(ref addr)) => (mem::transmute(addr), mem::size_of::<libc::sockaddr_in>() as libc::socklen_t),
- SockAddr::Inet(InetAddr::V6(ref addr)) => (mem::transmute(addr), mem::size_of::<libc::sockaddr_in6>() as libc::socklen_t),
- SockAddr::Unix(UnixAddr(ref addr, len)) => (mem::transmute(addr), (len + offset_of!(libc::sockaddr_un, sun_path)) as libc::socklen_t),
+ SockAddr::Inet(InetAddr::V4(ref addr)) => (
+ &*(addr as *const libc::sockaddr_in as *const libc::sockaddr),
+ mem::size_of_val(addr) as libc::socklen_t
+ ),
+ SockAddr::Inet(InetAddr::V6(ref addr)) => (
+ &*(addr as *const libc::sockaddr_in6 as *const libc::sockaddr),
+ mem::size_of_val(addr) as libc::socklen_t
+ ),
+ SockAddr::Unix(UnixAddr(ref addr, len)) => (
+ &*(addr as *const libc::sockaddr_un as *const libc::sockaddr),
+ (len + offset_of!(libc::sockaddr_un, sun_path)) as libc::socklen_t
+ ),
#[cfg(any(target_os = "android", target_os = "linux"))]
- SockAddr::Netlink(NetlinkAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_nl>() as libc::socklen_t),
+ SockAddr::Netlink(NetlinkAddr(ref sa)) => (
+ &*(sa as *const libc::sockaddr_nl as *const libc::sockaddr),
+ mem::size_of_val(sa) as libc::socklen_t
+ ),
#[cfg(any(target_os = "android", target_os = "linux"))]
- SockAddr::Alg(AlgAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_alg>() as libc::socklen_t),
+ SockAddr::Alg(AlgAddr(ref sa)) => (
+ &*(sa as *const libc::sockaddr_alg as *const libc::sockaddr),
+ mem::size_of_val(sa) as libc::socklen_t
+ ),
#[cfg(any(target_os = "ios", target_os = "macos"))]
- SockAddr::SysControl(SysControlAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_ctl>() as libc::socklen_t),
+ SockAddr::SysControl(SysControlAddr(ref sa)) => (
+ &*(sa as *const libc::sockaddr_ctl as *const libc::sockaddr),
+ mem::size_of_val(sa) as libc::socklen_t
+
+ ),
#[cfg(any(target_os = "android", target_os = "linux"))]
- SockAddr::Link(LinkAddr(ref ether_addr)) => (mem::transmute(ether_addr), mem::size_of::<libc::sockaddr_ll>() as libc::socklen_t),
+ SockAddr::Link(LinkAddr(ref addr)) => (
+ &*(addr as *const libc::sockaddr_ll as *const libc::sockaddr),
+ mem::size_of_val(addr) as libc::socklen_t
+ ),
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
- SockAddr::Link(LinkAddr(ref ether_addr)) => (mem::transmute(ether_addr), mem::size_of::<libc::sockaddr_dl>() as libc::socklen_t),
+ SockAddr::Link(LinkAddr(ref addr)) => (
+ &*(addr as *const libc::sockaddr_dl as *const libc::sockaddr),
+ mem::size_of_val(addr) as libc::socklen_t
+ ),
#[cfg(target_os = "linux")]
- SockAddr::Vsock(VsockAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_vm>() as libc::socklen_t),
+ SockAddr::Vsock(VsockAddr(ref sa)) => (
+ &*(sa as *const libc::sockaddr_vm as *const libc::sockaddr),
+ mem::size_of_val(sa) as libc::socklen_t
+ ),
}
}
}
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 0bb7b2f3..8ea7fb9f 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -1074,7 +1074,7 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result<usize> {
/// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html)
pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
unsafe {
- let addr: sockaddr_storage = mem::zeroed();
+ let mut addr: sockaddr_storage = mem::zeroed();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
let ret = Errno::result(libc::recvfrom(
@@ -1082,7 +1082,7 @@ pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
buf.as_ptr() as *mut c_void,
buf.len() as size_t,
0,
- mem::transmute(&addr),
+ &mut addr as *mut libc::sockaddr_storage as *mut libc::sockaddr,
&mut len as *mut socklen_t))?;
sockaddr_storage_to_addr(&addr, len as usize)
@@ -1188,10 +1188,14 @@ pub fn setsockopt<O: SetSockOpt>(fd: RawFd, opt: O, val: &O::Val) -> Result<()>
/// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html)
pub fn getpeername(fd: RawFd) -> Result<SockAddr> {
unsafe {
- let addr: sockaddr_storage = mem::uninitialized();
+ let mut addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
- let ret = libc::getpeername(fd, mem::transmute(&addr), &mut len);
+ let ret = libc::getpeername(
+ fd,
+ &mut addr as *mut libc::sockaddr_storage as *mut libc::sockaddr,
+ &mut len
+ );
Errno::result(ret)?;
@@ -1204,10 +1208,14 @@ pub fn getpeername(fd: RawFd) -> Result<SockAddr> {
/// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html)
pub fn getsockname(fd: RawFd) -> Result<SockAddr> {
unsafe {
- let addr: sockaddr_storage = mem::uninitialized();
+ let mut addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
- let ret = libc::getsockname(fd, mem::transmute(&addr), &mut len);
+ let ret = libc::getsockname(
+ fd,
+ &mut addr as *mut libc::sockaddr_storage as *mut libc::sockaddr,
+ &mut len
+ );
Errno::result(ret)?;