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.
This commit is contained in:
Nick Mathewson 2016-06-15 17:25:53 -04:00
parent 327d4c11dd
commit 7b54d7ebbd
6 changed files with 19 additions and 7 deletions

View File

@ -335,7 +335,7 @@ tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr)
} else if (ent->h_addrtype == AF_INET6) { } else if (ent->h_addrtype == AF_INET6) {
tor_addr_from_in6(addr, (struct in6_addr*) ent->h_addr); tor_addr_from_in6(addr, (struct in6_addr*) ent->h_addr);
} else { } else {
tor_assert(0); /* gethostbyname() returned a bizarre addrtype */ tor_assert(0); // LCOV_EXCL_LINE: gethostbyname() returned bizarre type
} }
return 0; return 0;
} }
@ -906,8 +906,10 @@ tor_addr_is_loopback(const tor_addr_t *addr)
case AF_UNSPEC: case AF_UNSPEC:
return 0; return 0;
default: default:
/* LCOV_EXCL_START */
tor_fragile_assert(); tor_fragile_assert();
return 0; 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: case AF_UNSPEC:
break; break;
default: 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: { case AF_INET6: {
if (mbits > 128) if (mbits > 128)
mbits = 128; mbits = 128;
const uint8_t *a1 = tor_addr_to_in6_addr8(addr1); const uint8_t *a1 = tor_addr_to_in6_addr8(addr1);
const uint8_t *a2 = tor_addr_to_in6_addr8(addr2); const uint8_t *a2 = tor_addr_to_in6_addr8(addr2);
const int bytes = mbits >> 3; const int bytes = mbits >> 3;
@ -1112,8 +1115,10 @@ tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
} }
} }
default: default:
/* LCOV_EXCL_START */
tor_fragile_assert(); tor_fragile_assert();
return 0; return 0;
/* LCOV_EXCL_STOP */
} }
} else if (how == CMP_EXACT) { } else if (how == CMP_EXACT) {
/* Unequal families and an exact comparison? Stop now! */ /* Unequal families and an exact comparison? Stop now! */
@ -1166,8 +1171,10 @@ tor_addr_hash(const tor_addr_t *addr)
case AF_INET6: case AF_INET6:
return siphash24g(&addr->addr.in6_addr.s6_addr, 16); return siphash24g(&addr->addr.in6_addr.s6_addr, 16);
default: default:
/* LCOV_EXCL_START */
tor_fragile_assert(); tor_fragile_assert();
return 0; return 0;
/* LCOV_EXCL_END */
} }
} }

View File

@ -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 128: c = EVP_aes_128_ecb(); break;
case 192: c = EVP_aes_192_ecb(); break; case 192: c = EVP_aes_192_ecb(); break;
case 256: c = EVP_aes_256_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); EVP_EncryptInit(&cipher->key.evp, c, (const unsigned char*)key, NULL);
cipher->using_evp = 1; cipher->using_evp = 1;

View File

@ -526,8 +526,10 @@ tor_asprintf(char **strp, const char *fmt, ...)
r = tor_vasprintf(strp, fmt, args); r = tor_vasprintf(strp, fmt, args);
va_end(args); va_end(args);
if (!*strp || r < 0) { if (!*strp || r < 0) {
/* LCOV_EXCL_START */
log_err(LD_BUG, "Internal error in asprintf"); log_err(LD_BUG, "Internal error in asprintf");
tor_assert(0); tor_assert(0);
/* LCOV_EXCL_STOP */
} }
return r; 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 /* If we get here, then gmtime/localtime failed without getting an extreme
* value for *timep */ * value for *timep */
/* LCOV_EXCL_START */
tor_fragile_assert(); tor_fragile_assert();
r = resultbuf; r = resultbuf;
memset(resultbuf, 0, sizeof(struct tm)); memset(resultbuf, 0, sizeof(struct tm));
outcome="can't recover"; outcome="can't recover";
/* LCOV_EXCL_STOP */
done: done:
log_warn(LD_BUG, "%s("I64_FORMAT") failed with error %s: %s", log_warn(LD_BUG, "%s("I64_FORMAT") failed with error %s: %s",
islocal?"localtime":"gmtime", islocal?"localtime":"gmtime",

View File

@ -75,7 +75,7 @@ sev_to_string(int severity)
case LOG_ERR: return "err"; case LOG_ERR: return "err";
default: /* Call assert, not tor_assert, since tor_assert default: /* Call assert, not tor_assert, since tor_assert
* calls log on failure. */ * 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; return (domain & (LD_BUG|LD_NOFUNCNAME)) == LD_BUG;
default: default:
/* Call assert, not tor_assert, since tor_assert calls log on failure. */ /* Call assert, not tor_assert, since tor_assert calls log on failure. */
assert(0); return 0; assert(0); return 0; // LCOV_EXCL_LINE
} }
} }

View File

@ -2790,9 +2790,11 @@ unescape_string(const char *s, char **result, size_t *size_out)
if (size_out) *size_out = out - *result; if (size_out) *size_out = out - *result;
return cp+1; return cp+1;
case '\0': case '\0':
/* LCOV_EXCL_START */
tor_fragile_assert(); tor_fragile_assert();
tor_free(*result); tor_free(*result);
return NULL; return NULL;
/* LCOV_EXCL_STOP */
case '\\': case '\\':
switch (cp[1]) switch (cp[1])
{ {

View File

@ -249,7 +249,7 @@ base64_encode(char *dest, size_t destlen, const char *src, size_t srclen,
break; break;
default: default:
/* Something went catastrophically wrong. */ /* Something went catastrophically wrong. */
tor_fragile_assert(); tor_fragile_assert(); // LCOV_EXCL_LINE
return -1; return -1;
} }