Skip to content

Commit

Permalink
To add a SAFETY comment to the now function
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ZhangHanDong authored Dec 28, 2023
1 parent 7f82d3a commit 6e98ce2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/system/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit 6e98ce2

Please sign in to comment.