From f79cd11b7876cabd75ca12a6e61a446ac36b826d Mon Sep 17 00:00:00 2001 From: Ember Date: Sun, 5 Apr 2026 17:48:35 -0700 Subject: [PATCH] Fix division by zero on network watchdog expiry --- P25Control.cpp | 5 +++-- YSFControl.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/P25Control.cpp b/P25Control.cpp index d713bd0..d35c26e 100644 --- a/P25Control.cpp +++ b/P25Control.cpp @@ -803,8 +803,9 @@ void CP25Control::clock(unsigned int ms) m_networkWatchdog.clock(ms); if (m_networkWatchdog.hasExpired()) { - LogMessage("P25, network watchdog has expired, %.1f seconds, %u%% packet loss", float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("lost", float(m_netFrames) / 50.0F, float(m_netLost * 100U) / float(m_netFrames)); + unsigned int netLostPerc = (m_netFrames > 0U) ? (m_netLost * 100U) / m_netFrames : 0U; + LogMessage("P25, network watchdog has expired, %.1f seconds, %u%% packet loss", float(m_netFrames) / 50.0F, netLostPerc); + writeJSONNet("lost", float(m_netFrames) / 50.0F, float(netLostPerc)); m_networkWatchdog.stop(); m_netState = RPT_NET_STATE::IDLE; diff --git a/YSFControl.cpp b/YSFControl.cpp index 4b1c718..d545a78 100644 --- a/YSFControl.cpp +++ b/YSFControl.cpp @@ -1039,8 +1039,9 @@ void CYSFControl::writeNetwork() m_netN = n; if (end) { - LogMessage("YSF, received network end of transmission from %10.10s to DG-ID %u at %10.10s, %.1f seconds, %u%% packet loss", m_netSource, dgid, data + 4U, float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("end", float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); + unsigned int netLostPerc = (m_netFrames > 0U) ? (m_netLost * 100U) / m_netFrames : 0U; + LogMessage("YSF, received network end of transmission from %10.10s to DG-ID %u at %10.10s, %.1f seconds, %u%% packet loss", m_netSource, dgid, data + 4U, float(m_netFrames) / 10.0F, netLostPerc); + writeJSONNet("end", float(m_netFrames) / 10.0F, netLostPerc); writeEndNet(); } } @@ -1060,8 +1061,9 @@ void CYSFControl::clock(unsigned int ms) m_networkWatchdog.clock(ms); if (m_networkWatchdog.hasExpired()) { - LogMessage("YSF, network watchdog has expired, %.1f seconds, %u%% packet loss", float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("lost", float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); + unsigned int netLostPerc = (m_netFrames > 0U) ? (m_netLost * 100U) / m_netFrames : 0U; + LogMessage("YSF, network watchdog has expired, %.1f seconds, %u%% packet loss", float(m_netFrames) / 10.0F, netLostPerc); + writeJSONNet("lost", float(m_netFrames) / 10.0F, netLostPerc); writeEndNet(); } }