Kaynağa Gözat

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.
Nick Mathewson 8 yıl önce
ebeveyn
işleme
7b54d7ebbd

+ 9 - 2
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 */
   }
 }
 

+ 1 - 1
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;

+ 4 - 1
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",

+ 2 - 2
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
   }
 }
 

+ 2 - 0
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])
           {

+ 1 - 1
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;
   }