summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2021-01-13 09:48:00 -0500
committerNick Mathewson <nickm@torproject.org>2021-01-13 09:54:43 -0500
commitfa8ecf88202dfe3af9e02331ca9dee6768870911 (patch)
tree082628fb7330439775abefeec004e2a1eb21bb05 /src/lib
parent6c0f15500b3aa027c90d1c397d4504bb2f4dd41b (diff)
downloadtor-fa8ecf88202dfe3af9e02331ca9dee6768870911.tar.gz
tor-fa8ecf88202dfe3af9e02331ca9dee6768870911.zip
Better fix for #40241 (--enable-all-bugs-are-fatal and fallthrough)
This one should work on GCC _and_ on Clang. The previous version made Clang happier by not having unreachable "fallthrough" statements, but made GCC sad because GCC didn't think that the unconditional failures were really unconditional, and therefore _wanted_ a FALLTHROUGH. This patch adds a FALLTHROUGH_UNLESS_ALL_BUGS_ARE_FATAL macro that seems to please both GCC and Clang in this case: ordinarily it is a FALLTHROUGH, but when ALL_BUGS_ARE_FATAL is defined, it's an abort(). Fixes bug 40241 again. Bugfix on earlier fix for 40241, which was merged into maint-0.3.5 and forward, and released in 0.4.5.3-rc.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/log/util_bug.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lib/log/util_bug.h b/src/lib/log/util_bug.h
index 2a4d68127e..17e8d0c5a7 100644
--- a/src/lib/log/util_bug.h
+++ b/src/lib/log/util_bug.h
@@ -215,6 +215,17 @@
IF_BUG_ONCE__(ASSERT_PREDICT_UNLIKELY_(cond), \
IF_BUG_ONCE_VARNAME__(__LINE__))
+/**
+ * Use this macro after a nonfatal assertion, and before a case statement
+ * where you would want to fall through.
+ */
+#ifdef ALL_BUGS_ARE_FATAL
+#define FALLTHROUGH_UNLESS_ALL_BUGS_ARE_FATAL \
+ abort()
+#else
+#define FALLTHROUGH_UNLESS_ALL_BUGS_ARE_FATAL FALLTHROUGH
+#endif
+
/** Define this if you want Tor to crash when any problem comes up,
* so you can get a coredump and track things down. */
// #define tor_fragile_assert() tor_assert_unreached(0)