summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorAaron Marcher <me@drkhsh.at>2018-05-20 23:53:26 +0200
committerAaron Marcher <me@drkhsh.at>2018-05-20 23:53:26 +0200
commit806815778fe75f13b569a1b5fe6d6d74a50c89ff (patch)
tree98ae7b2554bef11cfcddad329eea71b686170213 /components
parentd8ce4e694217bc69e95372f705d023e71dd70115 (diff)
swap_perc: check for division by zero
Diffstat (limited to 'components')
-rw-r--r--components/swap.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/components/swap.c b/components/swap.c
index c005691..465ffd4 100644
--- a/components/swap.c
+++ b/components/swap.c
@@ -76,6 +76,10 @@
}
sscanf(match, "SwapFree: %ld kB\n", &free);
+ if (total == 0) {
+ return NULL;
+ }
+
return bprintf("%d%%", 100 * (total - free - cached) / total);
}