From b296c5fddd1fe1a929ab5242a2de6f50a09b5b32 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Wed, 22 Jun 2022 12:56:07 +0530 Subject: [PATCH] Check duration > 0 before calculating stream rates Avoid divide by zero error and/or inf/nan values --- client/streamstatsmodel.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/streamstatsmodel.cpp b/client/streamstatsmodel.cpp index 8d01f34..52d4688 100644 --- a/client/streamstatsmodel.cpp +++ b/client/streamstatsmodel.cpp @@ -163,20 +163,24 @@ QVariant StreamStatsModel::data(const QModelIndex &index, int role) const case kTxDuration: return QString("%L1").arg(aggrGuidStats_.value(guid).txDuration); case kAvgTxFrameRate: - return QString("%L1").arg( + return aggrGuidStats_.value(guid).txDuration <= 0 ? QString("-") : + QString("%L1").arg( aggrGuidStats_.value(guid).txPkts / aggrGuidStats_.value(guid).txDuration); case kAvgRxFrameRate: - return QString("%L1").arg( + return aggrGuidStats_.value(guid).txDuration <= 0 ? QString("-") : + QString("%L1").arg( aggrGuidStats_.value(guid).rxPkts / aggrGuidStats_.value(guid).txDuration); case kAvgTxBitRate: - return XLocale().toBitRateString( + return aggrGuidStats_.value(guid).txDuration <= 0 ? QString("-") : + XLocale().toBitRateString( (aggrGuidStats_.value(guid).txBytes + 24 * aggrGuidStats_.value(guid).txPkts) * 8 / aggrGuidStats_.value(guid).txDuration); case kAvgRxBitRate: - return XLocale().toBitRateString( + return aggrGuidStats_.value(guid).txDuration <= 0 ? QString("-") : + XLocale().toBitRateString( (aggrGuidStats_.value(guid).rxBytes + 24 * aggrGuidStats_.value(guid).rxPkts) * 8 / aggrGuidStats_.value(guid).txDuration);