util: Work around cppcheck bug 6936

While experimenting with cppcheck options, I hit several false positives
caused by this bug: https://trac.cppcheck.net/ticket/13227

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-11-06 17:54:20 +11:00 committed by Stefano Brivio
parent 6f913b3af0
commit 867db07fcf
2 changed files with 11 additions and 1 deletions

View file

@ -188,5 +188,5 @@ cppcheck: $(PASST_SRCS) $(HEADERS)
$(SYSTEM_INCLUDES:%=--suppress=unmatchedSuppression:%/*) \
--inline-suppr \
--suppress=unusedStructMember \
$(filter -D%,$(FLAGS) $(CFLAGS) $(CPPFLAGS)) \
$(filter -D%,$(FLAGS) $(CFLAGS) $(CPPFLAGS)) -D CPPCHECK_6936 \
$(PASST_SRCS) $(HEADERS)

10
util.h
View file

@ -68,6 +68,15 @@
#define STRINGIFY(x) #x
#define STR(x) STRINGIFY(x)
#ifdef CPPCHECK_6936
/* Some cppcheck versions get confused by aborts inside a loop, causing
* it to give false positive uninitialised variable warnings later in
* the function, because it doesn't realise the non-initialising path
* already exited. See https://trac.cppcheck.net/ticket/13227
*/
#define ASSERT(expr) \
((expr) ? (void)0 : abort())
#else
#define ASSERT(expr) \
do { \
if (!(expr)) { \
@ -79,6 +88,7 @@
abort(); \
} \
} while (0)
#endif
#ifdef P_tmpdir
#define TMPDIR P_tmpdir