Fix division by zero on network watchdog expiry

This commit is contained in:
Ember 2026-04-05 17:48:35 -07:00
parent a2309124c7
commit f79cd11b78
2 changed files with 9 additions and 6 deletions

View file

@ -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;