[hackers] [slstatus][PATCH] cpu_perc: Check for division by zero

From: Ingo Feinerer <feinerer_AT_logic.at>
Date: Thu, 14 Feb 2019 00:19:46 +0100

---
 components/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/components/cpu.c b/components/cpu.c
index d9bd018..47a10c5 100644
--- a/components/cpu.c
+++ b/components/cpu.c
_AT_@ -92,6 +92,11 @@
 			return NULL;
 		}
 
+		if (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE] ==
+		    b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]) {
+			return NULL;
+		}
+
 		return bprintf("%d", 100 *
 		               ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
 		                 a[CP_INTR]) -
-- 
2.20.1
Received on Thu Feb 14 2019 - 00:19:46 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 14 2019 - 00:24:22 CET