Browse Source

Add !(...) to BUG() log messages

They use the same code as reporting assertion failures, so we should
invert the sense of what we're "asserting".

Fixes bug 20093.
Nick Mathewson 9 years ago
parent
commit
2b39c927c7
2 changed files with 12 additions and 5 deletions
  1. 4 0
      changes/bug20093
  2. 8 5
      src/common/util_bug.h

+ 4 - 0
changes/bug20093

@@ -0,0 +1,4 @@
+  o Minor bugfixes (logging):
+    - When logging a message from the BUG() macro, be explicit about what
+      we were asserting. Previously we were confusing what we were asserting
+      with what the bug was. Fixes bug 20093; bugfix on 0.2.9.1-alpha.

+ 8 - 5
src/common/util_bug.h

@@ -65,7 +65,8 @@
 #define tor_assert_nonfatal_once(cond) tor_assert((cond))
 #define tor_assert_nonfatal_once(cond) tor_assert((cond))
 #define BUG(cond)                                                       \
 #define BUG(cond)                                                       \
   (PREDICT_UNLIKELY(cond) ?                                             \
   (PREDICT_UNLIKELY(cond) ?                                             \
-   (tor_assertion_failed_(SHORT_FILE__,__LINE__,__func__,#cond), abort(), 1) \
+   (tor_assertion_failed_(SHORT_FILE__,__LINE__,__func__,"!("#cond")"), \
+    abort(), 1)                                                         \
    : 0)
    : 0)
 #elif defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS)
 #elif defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS)
 #define tor_assert_nonfatal_unreached() STMT_NIL
 #define tor_assert_nonfatal_unreached() STMT_NIL
@@ -98,18 +99,19 @@
   STMT_END
   STMT_END
 #define BUG(cond)                                                       \
 #define BUG(cond)                                                       \
   (PREDICT_UNLIKELY(cond) ?                                             \
   (PREDICT_UNLIKELY(cond) ?                                             \
-   (tor_bug_occurred_(SHORT_FILE__,__LINE__,__func__,#cond,0), 1)       \
+   (tor_bug_occurred_(SHORT_FILE__,__LINE__,__func__,"!("#cond")",0), 1) \
    : 0)
    : 0)
 #endif
 #endif
 
 
 #ifdef __GNUC__
 #ifdef __GNUC__
 #define IF_BUG_ONCE__(cond,var)                                         \
 #define IF_BUG_ONCE__(cond,var)                                         \
-  if (( {                                                                \
+  if (( {                                                               \
       static int var = 0;                                               \
       static int var = 0;                                               \
       int bool_result = (cond);                                         \
       int bool_result = (cond);                                         \
       if (PREDICT_UNLIKELY(bool_result) && !var) {                      \
       if (PREDICT_UNLIKELY(bool_result) && !var) {                      \
         var = 1;                                                        \
         var = 1;                                                        \
-        tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, #cond, 1);  \
+        tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__,             \
+                          "!("#cond")", 1);                             \
       }                                                                 \
       }                                                                 \
       PREDICT_UNLIKELY(bool_result); } ))
       PREDICT_UNLIKELY(bool_result); } ))
 #else
 #else
@@ -118,7 +120,8 @@
   if (PREDICT_UNLIKELY(cond)) ?                                         \
   if (PREDICT_UNLIKELY(cond)) ?                                         \
       (var ? 1 :                                                        \
       (var ? 1 :                                                        \
        (var=1,                                                          \
        (var=1,                                                          \
-        tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, #cond, 1),  \
+        tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__,             \
+                           "!("#cond")", 1),                            \
         1))                                                             \
         1))                                                             \
       : 0)
       : 0)
 #endif
 #endif