]> granicus.if.org Git - sysstat/commitdiff
Remove int-in-bool-context warnings
authorSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 9 Jul 2018 15:21:21 +0000 (17:21 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 9 Jul 2018 15:21:21 +0000 (17:21 +0200)
Recent gcc versions think the code used in SREALLOC() macro might be
wrong because we use the result of a multiplication as a boolean value:

In file included from sa.h:11,
                 from sadc.c:37:
sadc.c: In function ‘sa_sys_init’:
sadc.c:336:55: warning: ‘*’ in boolean context, suggest ‘&&’ instead [-Wint-in-bool-context]
      (size_t) act[i]->msize * (size_t) act[i]->nr_ini * (size_t) act[i]->nr2);
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
common.h:125:16: note: in definition of macro ‘SREALLOC’
            if (SIZE) {       \
                ^~~~

Add a comparison to zero to make clear to gcc that the code is actually
fine.

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

index e9136fa0ccf5ca4acde74b8151bcd5299e3b431f..09b64ab6f62f3fc7bd8125828c10c0102c637af6 100644 (file)
--- a/common.h
+++ b/common.h
 /* Allocate and init structure */
 #define SREALLOC(S, TYPE, SIZE)        do {                                                             \
                                        TYPE *_p_ = S;                                           \
-                                       if (SIZE) {                                              \
+                                       if ((SIZE) != 0) {                                       \
                                                if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \
                                                        perror("realloc");                       \
                                                        exit(4);                                 \