Skip to content

Commit

Permalink
pt: fix possible (yet highly unprobable) division by 0
Browse files Browse the repository at this point in the history
Fixed Coverity #200087, #200079, #200002, #200015

(cherry picked from commit 009e8ef)
  • Loading branch information
razvancrainea committed Jan 29, 2020
1 parent f525231 commit 9e216d3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pt_load.c
Expand Up @@ -253,6 +253,8 @@ unsigned int pt_get_rt_load(int _)
SUM_UP_LOAD( usec_now, n, ST, 1);
summed_procs++;
}
if (!summed_procs)
return 0;

return (used*100/(ST_WINDOW_TIME*summed_procs));
}
Expand All @@ -275,6 +277,8 @@ unsigned int pt_get_1m_load(int _)
SUM_UP_LOAD( usec_now, n, LT, LT_1m_RATIO);
summed_procs++;
}
if (!summed_procs)
return 0;

return (used*100/((long long)LT_WINDOW_TIME*summed_procs*LT_1m_RATIO));
}
Expand All @@ -297,6 +301,8 @@ unsigned int pt_get_10m_load(int _)
SUM_UP_LOAD( usec_now, n, LT, 1);
summed_procs++;
}
if (!summed_procs)
return 0;

return (used*100/((long long)LT_WINDOW_TIME*summed_procs));
}
Expand All @@ -318,6 +324,8 @@ unsigned int pt_get_rt_loadall(int _)
SUM_UP_LOAD( usec_now, n, ST, 1);
summed_procs++;
}
if (!summed_procs)
return 0;

return (used*100/((long long)ST_WINDOW_TIME*summed_procs));
}
Expand All @@ -339,6 +347,8 @@ unsigned int pt_get_1m_loadall(int _)
SUM_UP_LOAD( usec_now, n, LT, LT_1m_RATIO);
summed_procs++;
}
if (!summed_procs)
return 0;

return (used*100/((long long)LT_WINDOW_TIME*summed_procs*LT_1m_RATIO));
}
Expand All @@ -360,6 +370,8 @@ unsigned int pt_get_10m_loadall(int _)
SUM_UP_LOAD( usec_now, n, LT, 1);
summed_procs++;
}
if (!summed_procs)
return 0;

return (used*100/((long long)LT_WINDOW_TIME*summed_procs));
}
Expand Down

0 comments on commit 9e216d3

Please sign in to comment.