aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-11-06 17:54:20 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-11-07 12:47:24 +0100
commit867db07fcfc24d0918fa92f98e26fc8f9bf40253 (patch)
tree19aa1acf8fb9afabfdbc91dee9e7d55f242743e9
parent6f913b3af062a889f70758f8d3a458dcf0ac0cdd (diff)
downloadpasst-867db07fcfc24d0918fa92f98e26fc8f9bf40253.tar
passt-867db07fcfc24d0918fa92f98e26fc8f9bf40253.tar.gz
passt-867db07fcfc24d0918fa92f98e26fc8f9bf40253.tar.bz2
passt-867db07fcfc24d0918fa92f98e26fc8f9bf40253.tar.lz
passt-867db07fcfc24d0918fa92f98e26fc8f9bf40253.tar.xz
passt-867db07fcfc24d0918fa92f98e26fc8f9bf40253.tar.zst
passt-867db07fcfc24d0918fa92f98e26fc8f9bf40253.zip
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>
-rw-r--r--Makefile2
-rw-r--r--util.h10
2 files changed, 11 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 56bf2e8..3c82f50 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/util.h b/util.h
index 2858b10..0bf396a 100644
--- a/util.h
+++ b/util.h
@@ -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