Ver Fonte

swap_perc: check for division by zero

Aaron Marcher há 7 anos atrás
pai
commit
806815778f
1 ficheiros alterados com 4 adições e 0 exclusões
  1. 4 0
      components/swap.c

+ 4 - 0
components/swap.c

@@ -76,6 +76,10 @@
 		}
 		}
 		sscanf(match, "SwapFree: %ld kB\n", &free);
 		sscanf(match, "SwapFree: %ld kB\n", &free);
 
 
+		if (total == 0) {
+			return NULL;
+		}
+
 		return bprintf("%d%%", 100 * (total - free - cached) / total);
 		return bprintf("%d%%", 100 * (total - free - cached) / total);
 	}
 	}