Skip to content

Commit a0c4b26

Browse files
committed
main: fix possible division by zero
When there is no swap space, and the user passes "-S", we could be made to divide by zero. Found using the test suite.
1 parent 13cf12e commit a0c4b26

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ int main(int argc, char* argv[])
219219
}
220220

221221
if (swap_min) {
222-
swap_min_percent = 100 * swap_min / m.SwapTotal;
222+
if (m.SwapTotal > 0) {
223+
swap_min_percent = 100 * swap_min / m.SwapTotal;
224+
}
223225
} else {
224226
if (!swap_min_percent) {
225227
swap_min_percent = 10;

0 commit comments

Comments
 (0)