From 6e98ce2dc16da3a924988c334b452cb63a15d471 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 29 Dec 2023 00:03:30 +0800 Subject: [PATCH 1/2] To add a `SAFETY` comment to the now function The `unsafe` block should include necessary comments to complete the safety abstraction. In the implementation of the `now` function, necessary `SAFETY` comments should be added to explain its safety, with particular emphasis on the fact that `libc::clock_gettime` initializes the `spec`. --- src/system/time.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/system/time.rs b/src/system/time.rs index 0345bd852..2c40a5f4f 100644 --- a/src/system/time.rs +++ b/src/system/time.rs @@ -23,6 +23,8 @@ impl SystemTime { crate::cutils::cerr(unsafe { libc::clock_gettime(libc::CLOCK_BOOTTIME, spec.as_mut_ptr()) })?; + // SAFETY: The `libc::clock_gettime` will correctly initialize `spec`, + // otherwise it will return early with the `?` operator. let spec = unsafe { spec.assume_init() }; Ok(spec.into()) } From ec6d41a43e6f6d0ba278b80b98c95ef4417ffb6d Mon Sep 17 00:00:00 2001 From: blackanger Date: Fri, 29 Dec 2023 00:09:08 +0800 Subject: [PATCH 2/2] fixed fmt --- src/system/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/time.rs b/src/system/time.rs index 2c40a5f4f..a1de977e5 100644 --- a/src/system/time.rs +++ b/src/system/time.rs @@ -23,7 +23,7 @@ impl SystemTime { crate::cutils::cerr(unsafe { libc::clock_gettime(libc::CLOCK_BOOTTIME, spec.as_mut_ptr()) })?; - // SAFETY: The `libc::clock_gettime` will correctly initialize `spec`, + // SAFETY: The `libc::clock_gettime` will correctly initialize `spec`, // otherwise it will return early with the `?` operator. let spec = unsafe { spec.assume_init() }; Ok(spec.into())