Skip to content

Commit 4b1b305

Browse files
committed
Use MaybeUninit for clock_gettime's timespec.
1 parent 321690c commit 4b1b305

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/std/src/sys/unix/time.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ mod inner {
266266
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
267267
mod inner {
268268
use crate::fmt;
269+
use crate::mem::MaybeUninit;
269270
use crate::sys::cvt;
270271
use crate::time::Duration;
271272

@@ -350,9 +351,9 @@ mod inner {
350351

351352
impl Timespec {
352353
pub fn now(clock: clock_t) -> Timespec {
353-
let mut t = Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } };
354-
cvt(unsafe { libc::clock_gettime(clock, &mut t.t) }).unwrap();
355-
t
354+
let mut t = MaybeUninit::uninit();
355+
cvt(unsafe { libc::clock_gettime(clock, t.as_mut_ptr()) }).unwrap();
356+
Timespec { t: unsafe { t.assume_init() } }
356357
}
357358
}
358359
}

0 commit comments

Comments
 (0)