Skip to content

Commit

Permalink
main: fix possible division by zero
Browse files Browse the repository at this point in the history
When there is no swap space, and the user passes "-S",
we could be made to divide by zero.

Found using the test suite.
  • Loading branch information
rfjakob committed Jul 4, 2018
1 parent 13cf12e commit a0c4b26
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ int main(int argc, char* argv[])
}

if (swap_min) {
swap_min_percent = 100 * swap_min / m.SwapTotal;
if (m.SwapTotal > 0) {
swap_min_percent = 100 * swap_min / m.SwapTotal;
}
} else {
if (!swap_min_percent) {
swap_min_percent = 10;
Expand Down

0 comments on commit a0c4b26

Please sign in to comment.