]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: fix possibly undefined operation
authorPetr Uzel <petr.uzel@suse.cz>
Mon, 23 Apr 2012 08:43:38 +0000 (10:43 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 24 May 2012 10:17:51 +0000 (12:17 +0200)
With -Wall -Werror, compilation of lscpu.c fails with:

  Making all in sys-utils
  make[2]: Entering directory `/home/petr/upstream/util-linux/sys-utils'
  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I..  -include ../config.h -I../include -DLOCALEDIR=\"/usr/share/locale\"  -fsigned-char -Wall -Werror -MT lscpu.o -MD -MP -MF .deps/lscpu.Tpo -c -o lscpu.o lscpu.c
  lscpu.c: In function ‘print_parsable’:
  lscpu.c:971:7: error: operation on ‘p’ may be undefined [-Werror=sequence-point]
  cc1: all warnings being treated as errors

Fix by splitting the pointer increment to separate statement.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
sys-utils/lscpu.c

index 65e1eb6f110906d07dbee010356a7c3233f22eac..ee6969c3f161b052650ae287546d2a3ba8a323e0 100644 (file)
@@ -966,8 +966,10 @@ print_parsable(struct lscpu_desc *desc, int cols[], int ncols,
                         */
                        char *p = data + 1;
 
-                       while (p && *p != '\0')
-                               *p++ = tolower((unsigned int) *p);
+                       while (p && *p != '\0') {
+                               *p = tolower((unsigned int) *p);
+                               p++;
+                       }
                }
                fputs(data && *data ? data : "", stdout);
        }