Skip to content

Commit 21d66af

Browse files
committed
Saturate to u64::MAX
1 parent e85c521 commit 21d66af

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/tools/miri/src/clock.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ impl Instant {
4343
// `Duration` does not provide a nice constructor from a `u128` of nanoseconds,
4444
// so we have to implement this ourselves.
4545
// It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9).
46-
let seconds = u64::try_from(duration.saturating_div(1_000_000_000)).unwrap();
46+
// It will be saturated to u64::MAX seconds if the value after division exceeds u64::MAX.
47+
let seconds = u64::try_from(duration / 1_000_000_000).unwrap_or(u64::MAX);
4748
// It is impossible for nanosecond to overflow because u32::MAX > 1e9.
4849
let nanosecond = u32::try_from(duration.wrapping_rem(1_000_000_000)).unwrap();
4950
Duration::new(seconds, nanosecond)

0 commit comments

Comments
 (0)