From a9ec61db17b68c07816ef1be90e5d138597899e4 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Wed, 5 Aug 2020 12:18:32 +0100 Subject: [PATCH] Remove use of `MaybeUninit` in `ucred.rs` We can simply init the struct directly. There is no real need to use uninit memory here. --- library/std/src/sys/unix/ext/net.rs | 1 + library/std/src/sys/unix/ext/ucred.rs | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/library/std/src/sys/unix/ext/net.rs b/library/std/src/sys/unix/ext/net.rs index 930a6797000..ac8d6cf53ff 100644 --- a/library/std/src/sys/unix/ext/net.rs +++ b/library/std/src/sys/unix/ext/net.rs @@ -433,6 +433,7 @@ impl UnixStream { /// # Examples /// /// ```no_run + /// #![feature(peer_credentials_unix_socket)] /// use std::os::unix::net::UnixStream; /// /// fn main() -> std::io::Result<()> { diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index dec97ade126..efaa4d94437 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -31,7 +31,6 @@ pub use self::impl_bsd::peer_cred; #[cfg(any(target_os = "linux", target_os = "android"))] pub mod impl_linux { use super::UCred; - use crate::mem::MaybeUninit; use crate::os::unix::io::AsRawFd; use crate::os::unix::net::UnixStream; use crate::{io, mem}; @@ -46,9 +45,9 @@ pub mod impl_linux { assert!(ucred_size <= u32::max_value() as usize); let mut ucred_size = ucred_size as u32; + let mut ucred: ucred = ucred { pid: 1, uid: 1, gid: 1 }; unsafe { - let mut ucred: ucred = MaybeUninit::uninit().assume_init(); let ret = libc::getsockopt( socket.as_raw_fd(), libc::SOL_SOCKET, @@ -76,14 +75,12 @@ pub mod impl_linux { pub mod impl_bsd { use super::UCred; use crate::io; - use crate::mem::MaybeUninit; use crate::os::unix::io::AsRawFd; use crate::os::unix::net::UnixStream; pub fn peer_cred(socket: &UnixStream) -> io::Result { + let mut cred = UCred { uid: 1, gid: 1 }; unsafe { - // Create `cred` and attempt to populate it. - let mut cred: UCred = MaybeUninit::uninit().assume_init(); let ret = libc::getpeereid(socket.as_raw_fd(), &mut cred.uid, &mut cred.gid); if ret == 0 { Ok(cred) } else { Err(io::Error::last_os_error()) }