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
---
Makefile | 2 +-
util.h | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index cb91535..0ba85b4 100644
--- a/Makefile
+++ b/Makefile
@@ -183,5 +183,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 fdc3af8..1a4dfd4 100644
--- a/util.h
+++ b/util.h
@@ -67,6 +67,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)) { \
@@ -78,6 +87,7 @@
abort(); \
} \
} while (0)
+#endif
#ifdef P_tmpdir
#define TMPDIR P_tmpdir
--
2.47.0