diff options
| author | tiif <pekyuan@gmail.com> | 2024-06-09 17:58:21 +0800 |
|---|---|---|
| committer | tiif <pekyuan@gmail.com> | 2024-06-09 18:00:58 +0800 |
| commit | 21d66afb8f9f3736fcd2a2ff82f1d7aa31f15915 (patch) | |
| tree | 4436c38b512f8e010b513a03e68ef227e6561387 | |
| parent | e85c521f371ff6f5ffd813ccc453827064d2473d (diff) | |
| download | rust-21d66afb8f9f3736fcd2a2ff82f1d7aa31f15915.tar.gz rust-21d66afb8f9f3736fcd2a2ff82f1d7aa31f15915.zip | |
Saturate to u64::MAX
| -rw-r--r-- | src/tools/miri/src/clock.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index e730f523c7b..de6e883f117 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -43,7 +43,8 @@ impl Instant { // `Duration` does not provide a nice constructor from a `u128` of nanoseconds, // so we have to implement this ourselves. // It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9). - let seconds = u64::try_from(duration.saturating_div(1_000_000_000)).unwrap(); + // It will be saturated to u64::MAX seconds if the value after division exceeds u64::MAX. + let seconds = u64::try_from(duration / 1_000_000_000).unwrap_or(u64::MAX); // It is impossible for nanosecond to overflow because u32::MAX > 1e9. let nanosecond = u32::try_from(duration.wrapping_rem(1_000_000_000)).unwrap(); Duration::new(seconds, nanosecond) |
