diff mbox series

coverity: provide Coverity-friendly MIN_CONST and MAX_CONST

Message ID 20200629151642.11974-1-pbonzini@redhat.com
State New
Headers show
Series coverity: provide Coverity-friendly MIN_CONST and MAX_CONST | expand

Commit Message

Paolo Bonzini June 29, 2020, 3:16 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 0d26a1b9bd..4f4d4a3060 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -258,22 +258,29 @@  extern int daemon(int, int);
         typeof(1 ? (a) : (b)) _a = (a), _b = (b);       \
         _a < _b ? _a : _b;                              \
     })
-#define MIN_CONST(a, b)                                         \
-    __builtin_choose_expr(                                      \
-        __builtin_constant_p(a) && __builtin_constant_p(b),     \
-        (a) < (b) ? (a) : (b),                                  \
-        ((void)0))
+
 #undef MAX
 #define MAX(a, b)                                       \
     ({                                                  \
         typeof(1 ? (a) : (b)) _a = (a), _b = (b);       \
         _a > _b ? _a : _b;                              \
     })
+
+#ifdef __COVERITY__
+#define MIN_CONST(a, b) (a) < (b) ? (a) : (b)
+#define MAX_CONST(a, b) (a) > (b) ? (a) : (b)
+#else
+#define MIN_CONST(a, b)                                         \
+    __builtin_choose_expr(                                      \
+        __builtin_constant_p(a) && __builtin_constant_p(b),     \
+        (a) < (b) ? (a) : (b),                                  \
+        ((void)0))
 #define MAX_CONST(a, b)                                         \
     __builtin_choose_expr(                                      \
         __builtin_constant_p(a) && __builtin_constant_p(b),     \
         (a) > (b) ? (a) : (b),                                  \
         ((void)0))
+#endif
 
 /*
  * Minimum function that returns zero only if both values are zero.