Commit 28ac17f4 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

Use __attribute__((fallthrough)) rather than magic GCC comments.

GCC added an implicit-fallthrough warning a while back, where it
would complain if you had a nontrivial "case:" block that didn't end
with break, return, or something like that.  Clang recently added
the same thing.

GCC, however, would let you annotate a fall-through as intended by
any of various magic "/* fall through */" comments.  Clang, however,
only seems to like "__attribute__((fallthrough))".  Fortunately, GCC
accepts that too.

A previous commit in this branch defined a FALLTHROUGH macro to do
the right thing if GNUC is defined; here we replace all of our "fall
through" comments with uses of that macro.

This is an automated commit, made with the following perl one-liner:

  #!/usr/bin/perl -i -p
  s#/\* *falls? ?thr.*?\*/#FALLTHROUGH;#i;

(In order to avoid conflicts, I'm applying this script separately to
each maint branch. This is the 0.4.2 version.)
parent f954514b
......@@ -548,7 +548,7 @@ send_resolved_cell,(edge_connection_t *conn, uint8_t answer_type,
answer_type = RESOLVED_TYPE_ERROR;
/* We let this fall through and treat it as an error. */
}
/* Falls through. */
FALLTHROUGH;
case RESOLVED_TYPE_ERROR_TRANSIENT:
case RESOLVED_TYPE_ERROR:
{
......
......@@ -831,7 +831,7 @@ rend_client_report_intro_point_failure(extend_info_t *failed_intro,
log_warn(LD_BUG, "Unknown failure type %u. Removing intro point.",
failure_type);
tor_fragile_assert();
/* fall through */
FALLTHROUGH;
case INTRO_POINT_FAILURE_GENERIC:
rend_cache_intro_failure_note(failure_type,
(uint8_t *)failed_intro->identity_digest,
......
......@@ -37,8 +37,8 @@ digest_alg_to_nss_oid(digest_algorithm_t alg)
case DIGEST_SHA1: return SEC_OID_SHA1;
case DIGEST_SHA256: return SEC_OID_SHA256;
case DIGEST_SHA512: return SEC_OID_SHA512;
case DIGEST_SHA3_256: /* Fall through */
case DIGEST_SHA3_512: /* Fall through */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512: FALLTHROUGH;
default:
return SEC_OID_UNKNOWN;
}
......@@ -85,12 +85,12 @@ static bool
library_supports_digest(digest_algorithm_t alg)
{
switch (alg) {
case DIGEST_SHA1: /* Fall through */
case DIGEST_SHA256: /* Fall through */
case DIGEST_SHA1: FALLTHROUGH;
case DIGEST_SHA256: FALLTHROUGH;
case DIGEST_SHA512:
return true;
case DIGEST_SHA3_256: /* Fall through */
case DIGEST_SHA3_512: /* Fall through */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512: FALLTHROUGH;
default:
return false;
}
......@@ -197,8 +197,8 @@ crypto_digest_alloc_bytes(digest_algorithm_t alg)
#define END_OF_FIELD(f) (offsetof(crypto_digest_t, f) + \
STRUCT_FIELD_SIZE(crypto_digest_t, f))
switch (alg) {
case DIGEST_SHA1: /* Fall through */
case DIGEST_SHA256: /* Fall through */
case DIGEST_SHA1: FALLTHROUGH;
case DIGEST_SHA256: FALLTHROUGH;
case DIGEST_SHA512:
return END_OF_FIELD(d.ctx);
case DIGEST_SHA3_256:
......@@ -224,8 +224,8 @@ crypto_digest_new_internal(digest_algorithm_t algorithm)
switch (algorithm)
{
case DIGEST_SHA1: /* fall through */
case DIGEST_SHA256: /* fall through */
case DIGEST_SHA1: FALLTHROUGH;
case DIGEST_SHA256: FALLTHROUGH;
case DIGEST_SHA512:
r->d.ctx = PK11_CreateDigestContext(digest_alg_to_nss_oid(algorithm));
if (BUG(!r->d.ctx)) {
......@@ -312,8 +312,8 @@ crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
* just doing it ourselves. Hashes are fast.
*/
switch (digest->algorithm) {
case DIGEST_SHA1: /* fall through */
case DIGEST_SHA256: /* fall through */
case DIGEST_SHA1: FALLTHROUGH;
case DIGEST_SHA256: FALLTHROUGH;
case DIGEST_SHA512:
tor_assert(len <= UINT_MAX);
SECStatus s = PK11_DigestOp(digest->d.ctx,
......@@ -321,7 +321,7 @@ crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
(unsigned int)len);
tor_assert(s == SECSuccess);
break;
case DIGEST_SHA3_256: /* FALLSTHROUGH */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512:
keccak_digest_update(&digest->d.sha3, (const uint8_t *)data, len);
break;
......
......@@ -160,11 +160,11 @@ crypto_digest_alloc_bytes(digest_algorithm_t alg)
case DIGEST_SHA512:
return END_OF_FIELD(d.sha512);
#ifdef OPENSSL_HAS_SHA3
case DIGEST_SHA3_256: /* Fall through */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512:
return END_OF_FIELD(d.md);
#else
case DIGEST_SHA3_256: /* Fall through */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512:
return END_OF_FIELD(d.sha3);
#endif /* defined(OPENSSL_HAS_SHA3) */
......@@ -304,14 +304,14 @@ crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
SHA512_Update(&digest->d.sha512, (void*)data, len);
break;
#ifdef OPENSSL_HAS_SHA3
case DIGEST_SHA3_256: /* FALLSTHROUGH */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512: {
int r = EVP_DigestUpdate(digest->d.md, data, len);
tor_assert(r);
}
break;
#else /* !defined(OPENSSL_HAS_SHA3) */
case DIGEST_SHA3_256: /* FALLSTHROUGH */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512:
keccak_digest_update(&digest->d.sha3, (const uint8_t *)data, len);
break;
......@@ -377,7 +377,7 @@ crypto_digest_get_digest(crypto_digest_t *digest,
SHA512_Final(r, &tmpenv.d.sha512);
break;
//LCOV_EXCL_START
case DIGEST_SHA3_256: /* FALLSTHROUGH */
case DIGEST_SHA3_256: FALLTHROUGH;
case DIGEST_SHA3_512:
default:
log_warn(LD_BUG, "Handling unexpected algorithm %d", digest->algorithm);
......
......@@ -778,7 +778,7 @@ test_socks_truncated(void *ptr)
for (i = 0; i < ARRAY_LENGTH(commands); ++i) {
for (j = 0; j < commands[i].len; ++j) {
switch (commands[i].setup) {
default: /* Falls through */
default: FALLTHROUGH;
case NONE:
/* This test calls for no setup on the socks state. */
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment