Skip to content

Commit

Permalink
[CRM] Safety check for division by 0 (sonic-net#1569)
Browse files Browse the repository at this point in the history
Check if divisor is 0. If yes, log warning and skip division
  • Loading branch information
prsunny committed Dec 26, 2020
1 parent 9ed3026 commit 41fd2c4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,16 @@ void CrmOrch::checkCrmThresholds()

if (cnt.usedCounter != 0)
{
percentageUtil = (uint32_t)((cnt.usedCounter * 100) / (uint64_t)(cnt.usedCounter + cnt.availableCounter));
uint32_t dvsr = cnt.usedCounter + cnt.availableCounter;
if (dvsr != 0)
{
percentageUtil = (cnt.usedCounter * 100) / dvsr;
}
else
{
SWSS_LOG_WARN("%s Exception occured (div by Zero): Used count %u free count %u",
res.name.c_str(), cnt.usedCounter, cnt.availableCounter);
}
}

switch (res.thresholdType)
Expand Down

0 comments on commit 41fd2c4

Please sign in to comment.