[tor-commits] [tor/master] Mark src/common tor_assert(0)/tor_fragile_assert() unreached for coverage

nickm at torproject.org nickm at torproject.org
Thu Jun 16 13:37:59 UTC 2016


commit 7b54d7ebbd963a0a40b6ff5109ea0e3eedde534d
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Jun 15 17:25:53 2016 -0400

    Mark src/common tor_assert(0)/tor_fragile_assert() unreached for coverage
    
    I audited this to make sure I was only marking ones that really
    should be unreachable.
---
 src/common/address.c     | 11 +++++++++--
 src/common/aes.c         |  2 +-
 src/common/compat.c      |  5 ++++-
 src/common/log.c         |  4 ++--
 src/common/util.c        |  2 ++
 src/common/util_format.c |  2 +-
 6 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/common/address.c b/src/common/address.c
index 127e6a9..5cd7a8d 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -335,7 +335,7 @@ tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr)
       } else if (ent->h_addrtype == AF_INET6) {
         tor_addr_from_in6(addr, (struct in6_addr*) ent->h_addr);
       } else {
-        tor_assert(0); /* gethostbyname() returned a bizarre addrtype */
+        tor_assert(0); // LCOV_EXCL_LINE: gethostbyname() returned bizarre type
       }
       return 0;
     }
@@ -906,8 +906,10 @@ tor_addr_is_loopback(const tor_addr_t *addr)
     case AF_UNSPEC:
       return 0;
     default:
+      /* LCOV_EXCL_START */
       tor_fragile_assert();
       return 0;
+      /* LCOV_EXCL_STOP */
   }
 }
 
@@ -1028,7 +1030,7 @@ tor_addr_copy_tight(tor_addr_t *dest, const tor_addr_t *src)
     case AF_UNSPEC:
       break;
     default:
-      tor_fragile_assert();
+      tor_fragile_assert(); // LCOV_EXCL_LINE
     }
 }
 
@@ -1097,6 +1099,7 @@ tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
       case AF_INET6: {
         if (mbits > 128)
           mbits = 128;
+
         const uint8_t *a1 = tor_addr_to_in6_addr8(addr1);
         const uint8_t *a2 = tor_addr_to_in6_addr8(addr2);
         const int bytes = mbits >> 3;
@@ -1112,8 +1115,10 @@ tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
         }
       }
       default:
+        /* LCOV_EXCL_START */
         tor_fragile_assert();
         return 0;
+        /* LCOV_EXCL_STOP */
     }
   } else if (how == CMP_EXACT) {
     /* Unequal families and an exact comparison?  Stop now! */
@@ -1166,8 +1171,10 @@ tor_addr_hash(const tor_addr_t *addr)
   case AF_INET6:
     return siphash24g(&addr->addr.in6_addr.s6_addr, 16);
   default:
+    /* LCOV_EXCL_START */
     tor_fragile_assert();
     return 0;
+    /* LCOV_EXCL_END */
   }
 }
 
diff --git a/src/common/aes.c b/src/common/aes.c
index e9f78f4..db250c8 100644
--- a/src/common/aes.c
+++ b/src/common/aes.c
@@ -283,7 +283,7 @@ aes_set_key(aes_cnt_cipher_t *cipher, const char *key, int key_bits)
       case 128: c = EVP_aes_128_ecb(); break;
       case 192: c = EVP_aes_192_ecb(); break;
       case 256: c = EVP_aes_256_ecb(); break;
-      default: tor_assert(0);
+      default: tor_assert(0); // LCOV_EXCL_LINE
     }
     EVP_EncryptInit(&cipher->key.evp, c, (const unsigned char*)key, NULL);
     cipher->using_evp = 1;
diff --git a/src/common/compat.c b/src/common/compat.c
index 9d49b8f..023325b 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -526,8 +526,10 @@ tor_asprintf(char **strp, const char *fmt, ...)
   r = tor_vasprintf(strp, fmt, args);
   va_end(args);
   if (!*strp || r < 0) {
+    /* LCOV_EXCL_START */
     log_err(LD_BUG, "Internal error in asprintf");
     tor_assert(0);
+    /* LCOV_EXCL_STOP */
   }
   return r;
 }
@@ -2976,11 +2978,12 @@ correct_tm(int islocal, const time_t *timep, struct tm *resultbuf,
 
   /* If we get here, then gmtime/localtime failed without getting an extreme
    * value for *timep */
-
+  /* LCOV_EXCL_START */
   tor_fragile_assert();
   r = resultbuf;
   memset(resultbuf, 0, sizeof(struct tm));
   outcome="can't recover";
+  /* LCOV_EXCL_STOP */
  done:
   log_warn(LD_BUG, "%s("I64_FORMAT") failed with error %s: %s",
            islocal?"localtime":"gmtime",
diff --git a/src/common/log.c b/src/common/log.c
index e948ccf..51309aa 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -75,7 +75,7 @@ sev_to_string(int severity)
     case LOG_ERR:     return "err";
     default:          /* Call assert, not tor_assert, since tor_assert
                        * calls log on failure. */
-                      assert(0); return "UNKNOWN";
+                      assert(0); return "UNKNOWN"; // LCOV_EXCL_LINE
   }
 }
 
@@ -95,7 +95,7 @@ should_log_function_name(log_domain_mask_t domain, int severity)
       return (domain & (LD_BUG|LD_NOFUNCNAME)) == LD_BUG;
     default:
       /* Call assert, not tor_assert, since tor_assert calls log on failure. */
-      assert(0); return 0;
+      assert(0); return 0; // LCOV_EXCL_LINE
   }
 }
 
diff --git a/src/common/util.c b/src/common/util.c
index 1546fd1..b773aa7 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2790,9 +2790,11 @@ unescape_string(const char *s, char **result, size_t *size_out)
         if (size_out) *size_out = out - *result;
         return cp+1;
       case '\0':
+        /* LCOV_EXCL_START */
         tor_fragile_assert();
         tor_free(*result);
         return NULL;
+        /* LCOV_EXCL_STOP */
       case '\\':
         switch (cp[1])
           {
diff --git a/src/common/util_format.c b/src/common/util_format.c
index 8aae9e8..2dea187 100644
--- a/src/common/util_format.c
+++ b/src/common/util_format.c
@@ -249,7 +249,7 @@ base64_encode(char *dest, size_t destlen, const char *src, size_t srclen,
     break;
   default:
     /* Something went catastrophically wrong. */
-    tor_fragile_assert();
+    tor_fragile_assert(); // LCOV_EXCL_LINE
     return -1;
   }
 





More information about the tor-commits mailing list