about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorJoe Ellis <joe.ellis@arm.com>2020-08-05 12:18:32 +0100
committerJoe Ellis <joe.ellis@arm.com>2020-09-14 10:31:56 +0100
commita9ec61db17b68c07816ef1be90e5d138597899e4 (patch)
tree4926df472e5046fb71f6c37889486e0d0a5d332e /library/std/src/sys
parented20eff92be7bcd29ddc74f6bfa603f6698c9504 (diff)
downloadrust-a9ec61db17b68c07816ef1be90e5d138597899e4.tar.gz
rust-a9ec61db17b68c07816ef1be90e5d138597899e4.zip
Remove use of `MaybeUninit` in `ucred.rs`
We can simply init the struct directly. There is no real need to use
uninit memory here.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/ext/net.rs1
-rw-r--r--library/std/src/sys/unix/ext/ucred.rs7
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<UCred> {
+        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()) }