[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/53] coverity: provide Coverity-friendly MIN_CONST and MAX_CONST
From: |
Paolo Bonzini |
Subject: |
[PULL 11/53] coverity: provide Coverity-friendly MIN_CONST and MAX_CONST |
Date: |
Mon, 6 Jul 2020 12:41:13 -0400 |
From: Eric Blake <eblake@redhat.com>
Coverity has problems seeing through __builtin_choose_expr, which
result in it abandoning analysis of later functions that utilize a
definition that used MIN_CONST or MAX_CONST, such as in qemu-file.c:
50 DECLARE_BITMAP(may_free, MAX_IOV_SIZE);
CID 1429992 (#1 of 1): Unrecoverable parse warning (PARSE_ERROR)1.
expr_not_constant: expression must have a constant value
As has been done in the past (see 07d66672), it's okay to dumb things
down when compiling for static analyzers. (Of course, now the
syntax-checker has a false positive on our reference to
__COVERITY__...)
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Fixes: CID 1429992, CID 1429995, CID 1429997, CID 1429999
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200629162804.1096180-1-eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/qemu/osdep.h | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 0d26a1b9bd..0fc206ae61 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) \
@@ -258,22 +259,28 @@ 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; \
})
-#define MAX_CONST(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.
--
2.26.2
- [PULL 17/53] i386: hvf: Don't duplicate register reset, (continued)
- [PULL 17/53] i386: hvf: Don't duplicate register reset, Paolo Bonzini, 2020/07/06
- [PULL 18/53] i386: hvf: Clean up synchronize functions, Paolo Bonzini, 2020/07/06
- [PULL 21/53] MAINTAINERS: Add an 'overall' entry for accelerators, Paolo Bonzini, 2020/07/06
- [PULL 22/53] MAINTAINERS: Cover the HAX accelerator stub, Paolo Bonzini, 2020/07/06
- [PULL 23/53] Makefile: Remove dangerous EOL trailing backslash, Paolo Bonzini, 2020/07/06
- [PULL 24/53] Makefile: Write MINIKCONF variables as one entry per line, Paolo Bonzini, 2020/07/06
- [PULL 16/53] i386: hvf: Move Guest LMA reset to macvm_set_cr0(), Paolo Bonzini, 2020/07/06
- [PULL 25/53] accel/Kconfig: Extract accel selectors into their own config, Paolo Bonzini, 2020/07/06
- [PULL 01/53] tcg/svm: use host cr4 during NPT page table walk, Paolo Bonzini, 2020/07/06
- [PULL 19/53] MAINTAINERS: Add Cameron as HVF co-maintainer, Paolo Bonzini, 2020/07/06
- [PULL 11/53] coverity: provide Coverity-friendly MIN_CONST and MAX_CONST,
Paolo Bonzini <=
- [PULL 31/53] KVM: x86: believe what KVM says about WAITPKG, Paolo Bonzini, 2020/07/06
- [PULL 13/53] i386: hvf: Move synchronize functions to sysemu, Paolo Bonzini, 2020/07/06
- [PULL 15/53] i386: hvf: Make long mode enter and exit clearer, Paolo Bonzini, 2020/07/06
- [PULL 30/53] target/i386: implement undocumented "smsw r32" behavior, Paolo Bonzini, 2020/07/06
- [PULL 20/53] MAINTAINERS: Fix KVM path expansion glob, Paolo Bonzini, 2020/07/06
- [PULL 32/53] target/i386: sev: provide proper error reporting for query-sev-capabilities, Paolo Bonzini, 2020/07/06
- [PULL 26/53] accel/Kconfig: Add the TCG selector, Paolo Bonzini, 2020/07/06
- [PULL 40/53] pc: fix leak in pc_system_flash_cleanup_unused, Paolo Bonzini, 2020/07/06