Browse Source

swap_perc: check for division by zero

Aaron Marcher 7 years ago
parent
commit
806815778f
1 changed files with 4 additions and 0 deletions
  1. 4 0
      components/swap.c

+ 4 - 0
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);
 	}