]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Coverity deadcode shenanigans on BUG() macro.
authorNick Mathewson <nickm@torproject.org>
Fri, 28 Jul 2017 14:02:38 +0000 (10:02 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 28 Jul 2017 14:02:38 +0000 (10:02 -0400)
We don't actually want Coverity to complain when a BUG() check can
never fail, since such checks can prevent us from introducing bugs
later on.

Closes ticket 23054. Closes CID 14157201415724.

changes/bug23054 [new file with mode: 0644]
src/common/util_bug.c
src/common/util_bug.h

diff --git a/changes/bug23054 b/changes/bug23054
new file mode 100644 (file)
index 0000000..39006cd
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor features (static analysis):
+    - The BUG() macro has been changed slightly so that Coverity no
+      longer complains about dead code if the bug is impossible. Closes
+      ticket 23054.
index 3d990e3700b2e8c607f562192ff145a35a1558cb..cc1ac2ff84fce28afaa166bcfb4a2ad5d63eeeb9 100644 (file)
 #include "backtrace.h"
 #include "container.h"
 
+#ifdef __COVERITY__
+int bug_macro_deadcode_dummy__ = 0;
+#endif
+
 #ifdef TOR_UNIT_TESTS
 static void (*failed_assertion_cb)(void) = NULL;
 static int n_bugs_to_capture = 0;
index ae7e7a37fddaae962bb2af53f5096eb1a2042386..de39317d1ccb48e7a934212166d4cc5d990ad158 100644 (file)
  */
 
 #ifdef __COVERITY__
+extern int bug_macro_deadcode_dummy__;
 #undef BUG
 // Coverity defines this in global headers; let's override it.  This is a
 // magic coverity-only preprocessor thing.
-#nodef BUG(x) ((x)?(__coverity_panic__(),1):0)
+// We use this "deadcode_dummy__" trick to prevent coverity from
+// complaining about unreachable bug cases.
+#nodef BUG(x) ((x)?(__coverity_panic__(),1):(0+bug_macro_deadcode_dummy__))
 #endif
 
 #if defined(__COVERITY__) || defined(__clang_analyzer__)