We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
sub_timespec
1 parent d24a2ef commit ffcafa6Copy full SHA for ffcafa6
library/std/src/sys/pal/unix/time.rs
@@ -139,7 +139,8 @@ impl Timespec {
139
#[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
140
pub const fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> {
141
// FIXME: const PartialOrd
142
- let mut cmp = self.tv_sec - other.tv_sec;
+ // Use saturating arithmetic to avoid overflow when comparing extreme values
143
+ let mut cmp = self.tv_sec.saturating_sub(other.tv_sec);
144
if cmp == 0 {
145
cmp = self.tv_nsec.as_inner() as i64 - other.tv_nsec.as_inner() as i64;
146
}
0 commit comments