mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 20:23:21 +00:00
Remove use of MaybeUninit
in ucred.rs
We can simply init the struct directly. There is no real need to use uninit memory here.
This commit is contained in:
parent
ed20eff92b
commit
a9ec61db17
@ -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<()> {
|
||||
|
@ -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()) }
|
||||
|
Loading…
Reference in New Issue
Block a user