summaryrefslogtreecommitdiff
path: root/src/common/util_bug.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/util_bug.h')
-rw-r--r--src/common/util_bug.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common/util_bug.h b/src/common/util_bug.h
index ce54266b20..a5f78f2cd8 100644
--- a/src/common/util_bug.h
+++ b/src/common/util_bug.h
@@ -51,6 +51,11 @@
/* Non-fatal bug assertions. The "unreached" variants mean "this line should
* never be reached." The "once" variants mean "Don't log a warning more than
* once".
+ *
+ * The 'BUG' macro checks a boolean condition and logs an error message if it
+ * is true. Example usage:
+ * if (BUG(x == NULL))
+ * return -1;
*/
#ifdef ALL_BUGS_ARE_FATAL
@@ -58,11 +63,16 @@
#define tor_assert_nonfatal(cond) tor_assert((cond))
#define tor_assert_nonfatal_unreached_once() tor_assert(0)
#define tor_assert_nonfatal_once(cond) tor_assert((cond))
+#define BUG(cond) \
+ ((cond) ? \
+ (tor_assertion_failed_(SHORT_FILE__,__LINE__,__func__,#cond), abort(), 1) \
+ : 0)
#elif defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS)
#define tor_assert_nonfatal_unreached() STMT_NIL
#define tor_assert_nonfatal(cond) ((void)(cond))
#define tor_assert_nonfatal_unreached_once() STMT_NIL
#define tor_assert_nonfatal_once(cond) ((void)(cond))
+#define BUG(cond) ((cond) ? 1 : 0)
#else /* Normal case, !ALL_BUGS_ARE_FATAL, !DISABLE_ASSERTS_IN_UNIT_TESTS */
#define tor_assert_nonfatal_unreached() STMT_BEGIN \
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, NULL, 0); \
@@ -86,6 +96,10 @@
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, #cond, 1); \
} \
STMT_END
+#define BUG(cond) \
+ ((cond) ? \
+ (tor_bug_occurred_(SHORT_FILE__,__LINE__,__func__,#cond,0), 1) \
+ : 0)
#endif
/** Define this if you want Tor to crash when any problem comes up,