]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a module comment to util_bug.h
authorNick Mathewson <nickm@torproject.org>
Thu, 7 Sep 2017 13:31:30 +0000 (09:31 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 7 Sep 2017 13:31:30 +0000 (09:31 -0400)
Closes ticket 22824.

src/common/util_bug.h

index de39317d1ccb48e7a934212166d4cc5d990ad158..ce6565d92d112cbc403eeef45297e3da40a6c04d 100644 (file)
@@ -5,6 +5,32 @@
 
 /**
  * \file util_bug.h
+ *
+ * \brief Macros to manage assertions, fatal and non-fatal.
+ *
+ * Guidelines: All the different kinds of assertion in this file are for
+ * bug-checking only. Don't write code that can assert based on bad inputs.
+ *
+ * We provide two kinds of assertion here: "fatal" and "nonfatal". Use
+ * nonfatal assertions for any bug you can reasonably recover from -- and
+ * please, try to recover!  Many severe bugs in Tor have been caused by using
+ * a regular assertion when a nonfatal assertion would have been better.
+ *
+ * If you need to check a condition with a nonfatal assertion, AND recover
+ * from that same condition, consider using the BUG() macro inside a
+ * conditional.  For example:
+ *
+ * <code>
+ *  // wrong -- use tor_assert_nonfatal() if you just want an assertion.
+ *  BUG(ptr == NULL);
+ *
+ *  // okay, but needlessly verbose
+ *  tor_assert_nonfatal(ptr != NULL);
+ *  if (ptr == NULL) { ... }
+ *
+ *  // this is how we do it:
+ *  if (BUG(ptr == NULL)) { ... }
+ * </code>
  **/
 
 #ifndef TOR_UTIL_BUG_H