From 33de14aa419d3b263b943d58841b559d9c60eeb6 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 1 Apr 2018 08:18:56 +0200 Subject: [PATCH] mpstat: Check for possible division by zero Reassure Coverity by making sure that the total number of jiffies spent by all processors/nodes is not zero. This would be possible only if all processors were tickless. Signed-off-by: Sebastien GODARD --- mpstat.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mpstat.c b/mpstat.c index 98e7a36..d0e3059 100644 --- a/mpstat.c +++ b/mpstat.c @@ -755,6 +755,11 @@ void write_cpu_stats(int dis, unsigned long long deltot_jiffies, int prev, int c char *prev_string, char *curr_string, int tab, int *next, unsigned char offline_cpu_bitmap[]) { + if (!deltot_jiffies) { + /* CPU "all" cannot be tickless */ + deltot_jiffies = 1; + } + if (DISPLAY_JSON_OUTPUT(flags)) { if (*next) { printf(",\n"); @@ -1014,6 +1019,11 @@ void write_json_node_stats(int tab, unsigned long long deltot_jiffies, void write_node_stats(int dis, unsigned long long deltot_jiffies, int prev, int curr, char *prev_string, char *curr_string, int tab, int *next) { + if (!deltot_jiffies) { + /* CPU "all" cannot be tickless */ + deltot_jiffies = 1; + } + if (DISPLAY_JSON_OUTPUT(flags)) { if (*next) { printf(",\n"); -- 2.40.0