summaryrefslogtreecommitdiff
path: root/src/common/util_bug.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-04-05 09:40:51 -0400
committerNick Mathewson <nickm@torproject.org>2016-04-14 16:24:28 -0400
commita885271c08d2337b35c203c0b27509d0aa32dbf6 (patch)
tree0cb88f3d43fcc7a90be972d958d3146c1294c06b /src/common/util_bug.c
parent7865402106e9af273b9c887484b8371a899683ad (diff)
downloadtor-a885271c08d2337b35c203c0b27509d0aa32dbf6.tar.gz
tor-a885271c08d2337b35c203c0b27509d0aa32dbf6.zip
Add new tor_assert_nonfatal*() macros.
Unlike tor_assert(), these macros don't abort the process. They're good for checking conditions we want to warn about, but which don't warrant a full crash. This commit also changes the default implementation for tor_fragile_assert() to tor_assert_nonfatal_unreached_once(). Closes ticket 18613.
Diffstat (limited to 'src/common/util_bug.c')
-rw-r--r--src/common/util_bug.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/common/util_bug.c b/src/common/util_bug.c
index 139d139e8c..606c665163 100644
--- a/src/common/util_bug.c
+++ b/src/common/util_bug.c
@@ -26,3 +26,27 @@ tor_assertion_failed_(const char *fname, unsigned int line,
log_backtrace(LOG_ERR, LD_BUG, buf);
}
+
+void
+tor_bug_occurred_(const char *fname, unsigned int line,
+ const char *func, const char *expr,
+ int once)
+{
+ char buf[256];
+ const char *once_str = once ?
+ " (Future instances of this warning will be silenced.)": "";
+ if (! expr) {
+ log_warn(LD_BUG, "%s:%u: %s: This line should not have been reached.%s",
+ fname, line, func, once_str);
+ tor_snprintf(buf, sizeof(buf),
+ "Line unexpectedly reached at %s at %s:%u",
+ func, fname, line);
+ } else {
+ log_warn(LD_BUG, "%s:%u: %s: Non-fatal assertion %s failed.%s",
+ fname, line, func, expr, once_str);
+ tor_snprintf(buf, sizeof(buf),
+ "Non-fatal assertion %s failed in %s at %s:%u",
+ expr, func, fname, line);
+ }
+ log_backtrace(LOG_WARN, LD_BUG, buf);
+}