Use saturating_add to prevent overflow

This commit is contained in:
Stjepan Glavina 2020-10-02 18:17:45 +02:00
parent d4667889b4
commit 8b656241d5
2 changed files with 3 additions and 3 deletions

View File

@ -24,7 +24,7 @@ log = "0.4.11"
libc = "0.2.77"
[target.'cfg(windows)'.dependencies]
wepoll-sys = "2.0.0"
wepoll-sys = { path = "../wepoll" }
winapi = { version = "0.3.9", features = ["ioapiset", "winsock2"] }
[dev-dependencies]

View File

@ -81,8 +81,8 @@ impl Poller {
Some(t) => {
// Round up to a whole millisecond.
let mut ms = t.as_millis().try_into().unwrap_or(std::u64::MAX);
if Duration::from_millis(ms) < t {
ms += 1;
if Duration::from_millis(ms as u64) < t {
ms = ms.saturating_add(1);
}
ms.try_into().unwrap_or(std::i32::MAX)
}