]> granicus.if.org Git - sysstat/commitdiff
sadf: JSON: A_PWR_BAT: Add missing check
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 28 Dec 2022 17:25:08 +0000 (18:25 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 28 Dec 2022 17:25:08 +0000 (18:25 +0100)
Make sure that status code is not greater than upper limit before using.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
json_stats.c

index 4f6b2cfdd0ce570b761e6ef34eff7074971633eb..7b1a1db6079b21ed82b7086b0924e546ac70ffbd 100644 (file)
@@ -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, "