From 806815778fe75f13b569a1b5fe6d6d74a50c89ff Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 20 May 2018 23:53:26 +0200 Subject: swap_perc: check for division by zero --- components/swap.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'components/swap.c') 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); } -- cgit v1.2.3