From abcbe91116a3ce14f1777ee208d4fefa604caae0 Mon Sep 17 00:00:00 2001 From: jabu Date: Fri, 16 Aug 2024 06:13:03 -0500 Subject: [PATCH] fix a duration underflow --- CHANGELOG.md | 3 +++ src/connected.rs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a6b9b..1874119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.3.2 +- Fix a `Duration` underflow panic in `enet::connected` + # 0.3.1 - Add missing `enet::connected::Host::now` function diff --git a/src/connected.rs b/src/connected.rs index ad27bb3..c8879bb 100644 --- a/src/connected.rs +++ b/src/connected.rs @@ -873,7 +873,7 @@ impl Host { for peer in &mut self.peers { let mut disconnect = false; if let PeerState::AwaitingPeer { since, timeout, .. } = &mut peer.state { - if *since < now - *timeout { + if *since + *timeout < now { peer.state = PeerState::Disconnected { last_peer_ptr: None, }; @@ -887,7 +887,7 @@ impl Host { .. } = &mut peer.state { - if *last_send < now - Duration::from_secs(2) { + if *last_send + Duration::from_secs(2) < now { peer.state = PeerState::Disconnected { last_peer_ptr: last_peer_ptr.take(), };