Follow the Linux kernel's lead on "fallthrough"

The pseudo keyword 'fallthrough' is defined such that case statement
blocks must end with any of these keywords:
 * break;
 * fallthrough;
 * continue;
 * goto <label>;
 * return [expression];
 *
 *  gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes

The macro is defined either as

  __attribute__((__fallthrough__))

or as

  do {} while (0)  /* fallthrough */

not including the semicolon.

This change implements the Linux kernel style and updates several locations
where "/*fallthrough*/ and /* FALLTHROUGH */ were not previously replaced.

Externally imported code such as libedit, libtommath and sqlite are
restored to their unaltered state.

Change-Id: I69db8167b0d5884f55d96d72de3059a0235a1ba3
This commit is contained in:
Jeffrey Altman
2022-01-21 10:05:59 -05:00
committed by Jeffrey Altman
parent 02bd267fbd
commit 04527412e3
22 changed files with 39 additions and 62 deletions

View File

@@ -509,12 +509,12 @@ dnl Deal with switch FALLTHROUGH
AH_TOP([ AH_TOP([
#if defined(__GNUC__) #if defined(__GNUC__)
#if __GNUC__ >= 7 #if __GNUC__ >= 7
# define fallthrough __attribute__((fallthrough)); # define fallthrough __attribute__((fallthrough))
#else #else
# define fallthrough # define fallthrough do {} while (0) /* fallthrough */
#endif #endif
#else #else
# define fallthrough # define fallthrough do {} while (0) /* fallthrough */
#endif #endif
]) ])

View File

@@ -32,7 +32,7 @@
#ifndef __CONFIG_H__ #ifndef __CONFIG_H__
#define __CONFIG_H__ #define __CONFIG_H__
#define fallthrough #define fallthrough do {} while(0) /* fallthrough */
#ifndef RCSID #ifndef RCSID
#define RCSID(msg) \ #define RCSID(msg) \

View File

@@ -972,8 +972,7 @@ process_stream(krb5_context contextp,
INSIST(gctx.ctx == NULL); INSIST(gctx.ctx == NULL);
gctx.inprogress = 1; gctx.inprogress = 1;
/* FALLTHROUGH */ fallthrough;
fallthrough
case RPG_CONTINUE_INIT: { case RPG_CONTINUE_INIT: {
gss_name_t src_name = GSS_C_NO_NAME; gss_name_t src_name = GSS_C_NO_NAME;
krb5_data in; krb5_data in;

View File

@@ -62,8 +62,7 @@ copy_type (const char *from, const char *to, const Type *t, int preserve)
copy_primitive ("heim_integer", from, to); copy_primitive ("heim_integer", from, to);
break; break;
} }
/* FALLTHROUGH */ fallthrough;
fallthrough
case TBoolean: case TBoolean:
case TEnumerated : case TEnumerated :
fprintf(codefile, "*(%s) = *(%s);\n", to, from); fprintf(codefile, "*(%s) = *(%s);\n", to, from);

View File

@@ -56,7 +56,7 @@ free_type (const char *name, const Type *t, int preserve)
free_primitive ("heim_integer", name); free_primitive ("heim_integer", name);
break; break;
} }
/* fallthrough */ /* fallthrough; */
case TBoolean: case TBoolean:
case TEnumerated : case TEnumerated :
case TNull: case TNull:

View File

@@ -932,8 +932,7 @@ OM_uint32 GSSAPI_CALLCONV _gsskrb5_init_sec_context
time_rec); time_rec);
if (ret != GSS_S_COMPLETE) if (ret != GSS_S_COMPLETE)
break; break;
/* FALLTHROUGH */ fallthrough;
fallthrough
case INITIATOR_RESTART: case INITIATOR_RESTART:
ret = init_auth_restart(minor_status, ret = init_auth_restart(minor_status,
cred, cred,

View File

@@ -425,7 +425,6 @@ int main(int argc, char **argv)
case 'h': case 'h':
s_exit_code = EXIT_SUCCESS; s_exit_code = EXIT_SUCCESS;
/* FALLTHROUGH */ /* FALLTHROUGH */
fallthrough
default: default:
s_usage(argv[0]); s_usage(argv[0]);
} }

View File

@@ -2441,11 +2441,10 @@ hx509_verify_path(hx509_context context,
* EE checking below. * EE checking below.
*/ */
type = EE_CERT; type = EE_CERT;
/* FALLTHROUGH */ fallthrough;
} }
} }
/* FALLTHROUGH */ fallthrough;
fallthrough
case EE_CERT: case EE_CERT:
/* /*
* If there where any proxy certificates in the chain * If there where any proxy certificates in the chain

View File

@@ -182,8 +182,7 @@ fill_CMSIdentifier(const hx509_cert cert,
&id->u.subjectKeyIdentifier); &id->u.subjectKeyIdentifier);
if (ret == 0) if (ret == 0)
break; break;
/* FALLTHROUGH */ fallthrough;
fallthrough
case CMS_ID_NAME: { case CMS_ID_NAME: {
hx509_name name; hx509_name name;

View File

@@ -230,8 +230,7 @@ hx509_pem_read(hx509_context context,
where = INDATA; where = INDATA;
goto indata; goto indata;
} }
/* FALLTHROUGH */ fallthrough;
fallthrough
case INHEADER: case INHEADER:
if (buf[0] == '\0') { if (buf[0] == '\0') {
where = INDATA; where = INDATA;

View File

@@ -1046,7 +1046,7 @@ authorize_feat(hx509_request req, abitstring a, size_t n, int idx)
switch (ret) { switch (ret) {
case 0: case 0:
req->nauthorized++; req->nauthorized++;
/*fallthrough*/ fallthrough;
case -1: case -1:
return 0; return 0;
default: default:
@@ -1063,7 +1063,7 @@ reject_feat(hx509_request req, abitstring a, size_t n, int idx)
switch (ret) { switch (ret) {
case 0: case 0:
req->nauthorized--; req->nauthorized--;
/*fallthrough*/ fallthrough;
case -1: case -1:
return 0; return 0;
default: default:
@@ -1245,7 +1245,7 @@ san_map_type(GeneralName *san)
if (der_heim_oid_cmp(&san->u.otherName.type_id, map[i].oid) == 0) if (der_heim_oid_cmp(&san->u.otherName.type_id, map[i].oid) == 0)
return map[i].type; return map[i].type;
} }
/*fallthrough*/ fallthrough;
default: return HX509_SAN_TYPE_UNSUPPORTED; default: return HX509_SAN_TYPE_UNSUPPORTED;
} }
} }
@@ -1360,7 +1360,7 @@ hx509_request_get_san(hx509_request req,
case HX509_SAN_TYPE_REGISTERED_ID: case HX509_SAN_TYPE_REGISTERED_ID:
return der_print_heim_oid(&san->u.registeredID, '.', out); return der_print_heim_oid(&san->u.registeredID, '.', out);
case HX509_SAN_TYPE_XMPP: case HX509_SAN_TYPE_XMPP:
/*fallthrough*/ fallthrough;
case HX509_SAN_TYPE_MS_UPN: { case HX509_SAN_TYPE_MS_UPN: {
int ret; int ret;

View File

@@ -209,8 +209,7 @@ _kafs_derive_des_key(krb5_enctype enctype, void *keydata, size_t keylen,
ret = compress_parity_bits(keydata, &keylen); ret = compress_parity_bits(keydata, &keylen);
if (ret) if (ret)
return ret; return ret;
/* FALLTHROUGH */ fallthrough;
fallthrough
default: default:
if (enctype < 0) if (enctype < 0)
return KRB5_PROG_ETYPE_NOSUPP; return KRB5_PROG_ETYPE_NOSUPP;

View File

@@ -1192,8 +1192,7 @@ krb5_sendto_context(krb5_context context,
break; break;
} }
action = KRB5_SENDTO_KRBHST; action = KRB5_SENDTO_KRBHST;
/* FALLTHROUGH */ fallthrough;
fallthrough
case KRB5_SENDTO_KRBHST: case KRB5_SENDTO_KRBHST:
if (ctx->krbhst == NULL) { if (ctx->krbhst == NULL) {
ret = krb5_krbhst_init_flags(context, realm, type, ret = krb5_krbhst_init_flags(context, realm, type,
@@ -1215,8 +1214,7 @@ krb5_sendto_context(krb5_context context,
handle = heim_retain(ctx->krbhst); handle = heim_retain(ctx->krbhst);
} }
action = KRB5_SENDTO_TIMEOUT; action = KRB5_SENDTO_TIMEOUT;
/* FALLTHROUGH */ fallthrough;
fallthrough
case KRB5_SENDTO_TIMEOUT: case KRB5_SENDTO_TIMEOUT:
/* /*

View File

@@ -471,8 +471,7 @@ heim_digest_generate_challenge(heim_digest_t context)
break; break;
case HEIM_DIGEST_TYPE_AUTO: case HEIM_DIGEST_TYPE_AUTO:
context->type = HEIM_DIGEST_TYPE_RFC2831; context->type = HEIM_DIGEST_TYPE_RFC2831;
/* FALLTHROUGH */ fallthrough;
fallthrough
case HEIM_DIGEST_TYPE_RFC2831: case HEIM_DIGEST_TYPE_RFC2831:
asprintf(&challenge, "realm=\"%s\",nonce=\"%s\",qop=\"%s\",algorithm=md5-sess,charset=utf-8,maxbuf=%s", asprintf(&challenge, "realm=\"%s\",nonce=\"%s\",qop=\"%s\",algorithm=md5-sess,charset=utf-8,maxbuf=%s",
context->serverRealm, context->serverNonce, context->serverQOP, context->serverMaxbuf); context->serverRealm, context->serverNonce, context->serverQOP, context->serverMaxbuf);

View File

@@ -100,10 +100,10 @@ rk_base32_encode(const void *data, int size, char **str, enum rk_base32_flags fl
p[6] = chars[(c & 0x0000000000000003e0ULL) >> 5]; p[6] = chars[(c & 0x0000000000000003e0ULL) >> 5];
p[7] = chars[(c & 0x00000000000000001fULL) >> 0]; p[7] = chars[(c & 0x00000000000000001fULL) >> 0];
switch (i - size) { switch (i - size) {
case 4: p[2] = p[3] = '='; /*fallthrough*/ case 4: p[2] = p[3] = '='; fallthrough;
case 3: p[4] = '='; /*fallthrough*/ case 3: p[4] = '='; fallthrough;
case 2: p[5] = p[6] = '='; /*fallthrough*/ case 2: p[5] = p[6] = '='; fallthrough;
case 1: p[7] = '='; /*fallthrough*/ case 1: p[7] = '='; fallthrough;
default: break; default: break;
} }
p += 8; p += 8;

View File

@@ -28,7 +28,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
* *
**********************************************************************/ **********************************************************************/
#include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
@@ -148,7 +148,7 @@ int teardown_test(void)
strcmp(dirname + len + 1 - sizeof(TESTDIR)/sizeof(char), TESTDIR) == 0) { strcmp(dirname + len + 1 - sizeof(TESTDIR)/sizeof(char), TESTDIR) == 0) {
/* fallthrough */ fallthrough;
} else { } else {
/* did we create the directory? */ /* did we create the directory? */
@@ -162,7 +162,7 @@ int teardown_test(void)
fprintf(stderr, "Can't change to test directory. Aborting cleanup.\n"); fprintf(stderr, "Can't change to test directory. Aborting cleanup.\n");
return -1; return -1;
} else { } else {
/* fallthrough */ fallthrough;
} }
} else { } else {
return -1; return -1;

View File

@@ -129,8 +129,7 @@ rk_fnmatch(const char *pattern, const char *string, int flags)
--pattern; --pattern;
} }
} }
/* FALLTHROUGH */ fallthrough;
fallthrough
default: default:
if (c != *string++) if (c != *string++)
return (FNM_NOMATCH); return (FNM_NOMATCH);

View File

@@ -136,8 +136,7 @@ roken_get_homedir(char *home, size_t homesz)
} }
return home; return home;
} }
/* FALLTHROUGH */ fallthrough;
fallthrough
#else #else
#ifdef HAVE_GETPWNAM_R #ifdef HAVE_GETPWNAM_R
size_t buflen = 2048; size_t buflen = 2048;

View File

@@ -515,8 +515,7 @@ xyzprintf (struct snprintf_state *state, const char *char_format, va_list ap)
} }
case '\0' : case '\0' :
--format; --format;
/* FALLTHROUGH */ fallthrough;
fallthrough
case '%' : case '%' :
(*state->append_char)(state, c); (*state->append_char)(state, c);
++len; ++len;

View File

@@ -377,8 +377,7 @@ strftime (char *buf, size_t maxsize, const char *format,
break; break;
case '\0' : case '\0' :
--format; --format;
/* FALLTHROUGH */ fallthrough;
fallthrough
case '%' : case '%' :
ret = snprintf (buf, maxsize - n, ret = snprintf (buf, maxsize - n,
"%%"); "%%");

View File

@@ -424,8 +424,7 @@ strptime (const char *buf, const char *format, struct tm *timeptr)
abort (); abort ();
case '\0' : case '\0' :
--format; --format;
/* FALLTHROUGH */ fallthrough;
fallthrough
case '%' : case '%' :
if (*buf == '%') if (*buf == '%')
++buf; ++buf;

View File

@@ -205,22 +205,18 @@ wind_ucs4utf8(const uint32_t *in, size_t in_len, char *out, size_t *out_len)
case 4: case 4:
out[3] = (ch | 0x80) & 0xbf; out[3] = (ch | 0x80) & 0xbf;
ch = ch >> 6; ch = ch >> 6;
/* FALLTHROUGH */ fallthrough;
fallthrough
case 3: case 3:
out[2] = (ch | 0x80) & 0xbf; out[2] = (ch | 0x80) & 0xbf;
ch = ch >> 6; ch = ch >> 6;
/* FALLTHROUGH */ fallthrough;
fallthrough
case 2: case 2:
out[1] = (ch | 0x80) & 0xbf; out[1] = (ch | 0x80) & 0xbf;
ch = ch >> 6; ch = ch >> 6;
/* FALLTHROUGH */ fallthrough;
fallthrough
case 1: case 1:
out[0] = ch | first_char[len - 1]; out[0] = ch | first_char[len - 1];
/* FALLTHROUGH */ fallthrough;
fallthrough
default: default:
break; break;
} }
@@ -490,17 +486,14 @@ wind_ucs2utf8(const uint16_t *in, size_t in_len, char *out, size_t *out_len)
case 3: case 3:
out[2] = (ch | 0x80) & 0xbf; out[2] = (ch | 0x80) & 0xbf;
ch = ch >> 6; ch = ch >> 6;
/* FALLTHROUGH */ fallthrough;
fallthrough
case 2: case 2:
out[1] = (ch | 0x80) & 0xbf; out[1] = (ch | 0x80) & 0xbf;
ch = ch >> 6; ch = ch >> 6;
/* FALLTHROUGH */ fallthrough;
fallthrough
case 1: case 1:
out[0] = ch | first_char[len - 1]; out[0] = ch | first_char[len - 1];
/* FALLTHROUGH */ fallthrough;
fallthrough
default: default:
break; break;
} }