From: Sebastien GODARD Date: Sun, 1 Apr 2018 06:25:28 +0000 (+0200) Subject: sadc: Fix use of uninitialized variable X-Git-Tag: v11.7.3~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b9b4ddaa6be9e81353914a5e7c0529ae3487cb1;p=sysstat sadc: Fix use of uninitialized variable Coverity CID#267242. Signed-off-by: Sebastien GODARD --- diff --git a/sa_wrap.c b/sa_wrap.c index f46b3a6..c8cdc74 100644 --- a/sa_wrap.c +++ b/sa_wrap.c @@ -1071,7 +1071,7 @@ __read_funct_t wrap_read_fchost(struct activity *a) * * RETURNS: * Number of CPU for which statistics have to be be read. - * 1 means CPU "all", 2 means CPU 0, 3 means CPU 1, etc. + * 1 means CPU "all", 2 means CPU "all" and CPU 0, etc. * Or -1 if the buffer was too small and needs to be reallocated. *************************************************************************** */ @@ -1079,7 +1079,7 @@ int get_online_cpu_list(unsigned char online_cpu_bitmap[], int bitmap_size) { FILE *fp; char line[8192]; - int proc_nr; + int proc_nr = -2; if ((fp = fopen(STAT, "r")) == NULL) return 0; @@ -1091,13 +1091,13 @@ int get_online_cpu_list(unsigned char online_cpu_bitmap[], int bitmap_size) if (!strncmp(line, "cpu", 3)) { sscanf(line + 3, "%d", &proc_nr); - } - if (proc_nr + 1 > bitmap_size) { - fclose(fp); - return -1; + if (proc_nr + 1 > bitmap_size) { + fclose(fp); + return -1; + } + online_cpu_bitmap[proc_nr >> 3] |= 1 << (proc_nr & 0x07); } - online_cpu_bitmap[proc_nr >> 3] |= 1 << (proc_nr & 0x07); } fclose(fp);