Xinqi Bao's Git

swap_perc: check for division by zero
authorAaron Marcher <[email protected]>
Sun, 20 May 2018 21:53:26 +0000 (23:53 +0200)
committerAaron Marcher <[email protected]>
Sun, 20 May 2018 21:53:26 +0000 (23:53 +0200)
components/swap.c

index c005691..465ffd4 100644 (file)
                }
                sscanf(match, "SwapFree: %ld kB\n", &free);
 
+               if (total == 0) {
+                       return NULL;
+               }
+
                return bprintf("%d%%", 100 * (total - free - cached) / total);
        }