Skip to content

Commit

Permalink
[CRM] Safety check for division by 0 (#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 authored and yxieca committed Feb 17, 2021
1 parent 6055853 commit 44ffe5c
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 @@ -540,7 +540,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 44ffe5c

Please sign in to comment.