diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-06-24 06:27:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-24 06:27:16 +0200 |
| commit | 9892b3e9fe9a620ca9cf29c3415c4c8a07d1dcea (patch) | |
| tree | c601ffeda406bb0d8dabf8a3c9364e31e6c3a905 /library/std/src/sys | |
| parent | 3108dfacedbd48dc76d6e7a7d19dace7495dfb32 (diff) | |
| parent | fc50acae90ea11a43eb247f0249b676645c3d434 (diff) | |
| download | rust-9892b3e9fe9a620ca9cf29c3415c4c8a07d1dcea.tar.gz rust-9892b3e9fe9a620ca9cf29c3415c4c8a07d1dcea.zip | |
Rollup merge of #126854 - devnexen:std_unix_os_fallback_upd, r=Mark-Simulacrum
std::unix::os::home_dir: fallback's optimisation. we're using a guaranteed initialised field on success.
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/pal/unix/os.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/library/std/src/sys/pal/unix/os.rs b/library/std/src/sys/pal/unix/os.rs index 2e71ceceb58..40e2d1403ef 100644 --- a/library/std/src/sys/pal/unix/os.rs +++ b/library/std/src/sys/pal/unix/os.rs @@ -738,17 +738,17 @@ pub fn home_dir() -> Option<PathBuf> { n => n as usize, }; let mut buf = Vec::with_capacity(amt); - let mut passwd: libc::passwd = mem::zeroed(); + let mut p = mem::MaybeUninit::<libc::passwd>::uninit(); let mut result = ptr::null_mut(); match libc::getpwuid_r( libc::getuid(), - &mut passwd, + p.as_mut_ptr(), buf.as_mut_ptr(), buf.capacity(), &mut result, ) { 0 if !result.is_null() => { - let ptr = passwd.pw_dir as *const _; + let ptr = (*result).pw_dir as *const _; let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); Some(OsStringExt::from_vec(bytes)) } |
