Skip to content

Commit 9892b3e

Browse files
authored
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.
2 parents 3108dfa + fc50aca commit 9892b3e

File tree

1 file changed

+3
-3
lines changed
  • library/std/src/sys/pal/unix

1 file changed

+3
-3
lines changed

library/std/src/sys/pal/unix/os.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -738,17 +738,17 @@ pub fn home_dir() -> Option<PathBuf> {
738738
n => n as usize,
739739
};
740740
let mut buf = Vec::with_capacity(amt);
741-
let mut passwd: libc::passwd = mem::zeroed();
741+
let mut p = mem::MaybeUninit::<libc::passwd>::uninit();
742742
let mut result = ptr::null_mut();
743743
match libc::getpwuid_r(
744744
libc::getuid(),
745-
&mut passwd,
745+
p.as_mut_ptr(),
746746
buf.as_mut_ptr(),
747747
buf.capacity(),
748748
&mut result,
749749
) {
750750
0 if !result.is_null() => {
751-
let ptr = passwd.pw_dir as *const _;
751+
let ptr = (*result).pw_dir as *const _;
752752
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
753753
Some(OsStringExt::from_vec(bytes))
754754
}

0 commit comments

Comments
 (0)