]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Refactor the assertion-failure code into a function
authorNick Mathewson <nickm@torproject.org>
Fri, 19 Jul 2013 17:40:20 +0000 (13:40 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 19 Jul 2013 17:40:20 +0000 (13:40 -0400)
src/common/util.c
src/common/util.h

index 25ea1337117116fd00d47caab9440d3e6ada98a2..814eb1379b682c0021056f0082acefea91faa88c 100644 (file)
 #include <sys/wait.h>
 #endif
 
+/* =====
+ * Assertion helper.
+ * ===== */
+/** Helper for tor_assert: report the assertion failure. */
+void
+tor_assertion_failed_(const char *fname, unsigned int line,
+                      const char *func, const char *expr)
+{
+  log_err(LD_BUG, "%s:%u: %s: Assertion %s failed; aborting.",
+          fname, line, func, expr);
+  fprintf(stderr,"%s:%u: %s: Assertion %s failed; aborting.\n",
+          fname, line, func, expr);
+}
+
 /* =====
  * Memory management
  * ===== */
@@ -5057,4 +5071,3 @@ tor_weak_random_range(tor_weak_rng_t *rng, int32_t top)
   } while (result >= top);
   return result;
 }
-
index f6d828796d0228833cf4b181385d7895f8c5d4ad..1c92c4f5f0e9615b2ed20faef42a526644287254 100644 (file)
 /** Like assert(3), but send assertion failures to the log as well as to
  * stderr. */
 #define tor_assert(expr) STMT_BEGIN                                     \
-    if (PREDICT_UNLIKELY(!(expr))) {                                    \
-      log_err(LD_BUG, "%s:%d: %s: Assertion %s failed; aborting.",      \
-          SHORT_FILE__, __LINE__, __func__, #expr);                     \
-      fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n",      \
-              SHORT_FILE__, __LINE__, __func__, #expr);                 \
-      abort();                                                          \
-    } STMT_END
+  if (PREDICT_UNLIKELY(!(expr))) {                                      \
+    tor_assertion_failed_(SHORT_FILE__, __LINE__, __func__, #expr);     \
+    abort();                                                            \
+  } STMT_END
+
+void tor_assertion_failed_(const char *fname, unsigned int line,
+                           const char *func, const char *expr);
 
 /* If we're building with dmalloc, we want all of our memory allocation
  * functions to take an extra file/line pair of arguments.  If not, not.