From 32b9edeb91a7d9b9752083622d1ce400f45e42ea Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 25 Jul 2017 10:14:24 -0400 Subject: Fix build warnings from Coverity related to our BUG macro In the Linux kernel, the BUG() macro causes an instant panic. Our BUG() macro is different, however: it generates a nonfatal assertion failure, and is usable as an expression. Additionally, this patch tells util_bug.h to make all assertion failures into fatal conditions when we're building with a static analysis tool, so that the analysis tool can look for instances where they're reachable. Fixes bug 23030. --- src/common/util_bug.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/common/util_bug.h') diff --git a/src/common/util_bug.h b/src/common/util_bug.h index e02778110b..0695806911 100644 --- a/src/common/util_bug.h +++ b/src/common/util_bug.h @@ -58,6 +58,19 @@ * return -1; */ +#ifdef __COVERITY__ +#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) +#endif + +#if defined(__COVERITY__) || defined(__clang_analyzer__) +// We're running with a static analysis tool: let's treat even nonfatal +// assertion failures as something that we need to avoid. +#define ALL_BUGS_ARE_FATAL +#endif + #ifdef ALL_BUGS_ARE_FATAL #define tor_assert_nonfatal_unreached() tor_assert(0) #define tor_assert_nonfatal(cond) tor_assert((cond)) -- cgit v1.2.3-54-g00ecf