From: Sebastien GODARD Date: Wed, 28 Dec 2022 17:25:08 +0000 (+0100) Subject: sadf: JSON: A_PWR_BAT: Add missing check X-Git-Tag: v12.7.2~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=08637509cb07582d0752dcf041990317bd29cf28;p=sysstat sadf: JSON: A_PWR_BAT: Add missing check Make sure that status code is not greater than upper limit before using. Signed-off-by: Sebastien GODARD --- diff --git a/json_stats.c b/json_stats.c index 4f6b2cf..7b1a1db 100644 --- a/json_stats.c +++ b/json_stats.c @@ -2647,6 +2647,11 @@ __print_funct_t json_print_pwr_bat_stats(struct activity *a, int curr, int tab, } sep = TRUE; + /* Battery status code should not be greater than or equal to BAT_STS_NR */ + if (spbc->status >= BAT_STS_NR) { + spbc->status = 0; + } + xprintf0(tab, "{\"number\": %d, " "\"percent-capacity\": %u, " "\"variation\": %.2f, "