qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] coverity: provide Coverity-friendly MIN_CONST and MAX_CONST


From: Eric Blake
Subject: Re: [PATCH] coverity: provide Coverity-friendly MIN_CONST and MAX_CONST
Date: Mon, 29 Jun 2020 10:36:38 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

On 6/29/20 10:34 AM, Eric Blake wrote:
On 6/29/20 10:16 AM, Paolo Bonzini wrote:
Coverity's parser chokes on __builtin_choose_expr inside a constant
expression.  Since it is used only to raise compilation errors for
non-constant arguments, we can just assume there are no such errors
in the Coverity runs, and define MIN_CONST and MAX_CONST to the
"classic" ternary-operator-based definitions of minimum and maximum.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
  include/qemu/osdep.h | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

I wrote a variant in the meantime, and in comparing the two, the only major difference was that I added a line:

     Fixes: CID 1429992, CID 1429995, CID 1429997, CID 1429999

in the commit message, as well as a comment in osdep.h:

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 0d26a1b9bd07..98bc7156fa9b 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -250,7 +250,8 @@ extern int daemon(int, int);
   * Note that neither form is usable as an #if condition; if you truly
   * need to write conditional code that depends on a minimum or maximum
   * determined by the pre-processor instead of the compiler, you'll
- * have to open-code it.
+ * have to open-code it.  Sadly, Coverity is severely confused by the
+ * constant variants, so we have to dumb things down there.
   */
  #undef MIN
  #define MIN(a, b)                                       \



Oh, and the more significant difference that the syntax checker is right: we want the fallback definition to be enclosed in an outer (). Looks like we need v2.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]