diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2025-11-20 15:02:31 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2025-11-21 11:14:31 +0100 |
| commit | 246c6e8b4ba4ebbfdade510c86bb3a3796c6e723 (patch) | |
| tree | e83bf7945dfa3f25102c89665bc1874b3466d781 | |
| parent | 61f97fcd80fd5bf2ed24d223d18583804e49f66f (diff) | |
| download | mullvadvpn-246c6e8b4ba4ebbfdade510c86bb3a3796c6e723.tar.xz mullvadvpn-246c6e8b4ba4ebbfdade510c86bb3a3796c6e723.zip | |
Fix Unix time code using dangerous `as _` casts
| -rw-r--r-- | talpid-time/src/unix.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/talpid-time/src/unix.rs b/talpid-time/src/unix.rs index 02b51b06fa..8423aa0050 100644 --- a/talpid-time/src/unix.rs +++ b/talpid-time/src/unix.rs @@ -39,11 +39,11 @@ impl Instant { ) }; - if tv_sec < 0 { - return None; - } + // Return `None` if the duration would be negative + let secs = u64::try_from(tv_sec).ok()?; + let nanos = u32::try_from(tv_nsec).expect("tv_nsec outside expected range"); - Some(Duration::new(tv_sec as _, tv_nsec as _)) + Some(Duration::new(secs, nanos)) } pub fn duration_since(&self, earlier: Instant) -> Duration { |
