]> xenbits.xensource.com Git - libvirt.git/commitdiff
Use explicit boolean comparison in OOM check
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 22 Feb 2017 16:42:45 +0000 (16:42 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 23 Feb 2017 10:11:16 +0000 (10:11 +0000)
GCC 7 gets upset by

   if (!tmp && (size * count))

warning

  util/viralloc.c: In function 'virReallocN':
  util/viralloc.c:246:23: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]
     if (!tmp && (size * count)) {
                 ~~~~~~^~~~~~~~

Keep it happy by adding != 0 to the right hand expression
so it realizes we really are wanting to treat the result
of the arithmetic expression as a boolean

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/util/viralloc.c

index 812aa5b3f946a186efd58c994aef0e3f55fcb225..81f99d9e1ff4c5604d4782e72391eaa189caf5d9 100644 (file)
@@ -243,7 +243,7 @@ int virReallocN(void *ptrptr,
         return -1;
     }
     tmp = realloc(*(void**)ptrptr, size * count);
-    if (!tmp && (size * count)) {
+    if (!tmp && ((size * count) != 0)) {
         if (report)
             virReportOOMErrorFull(domcode, filename, funcname, linenr);
         return -1;