From ddc61136100b32346c4c4efa2bb6ddb5baedfb3e Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Fri, 14 Jan 2022 16:32:04 -0600 Subject: [PATCH] Use fallthrough statement attribute --- configure.ac | 13 +++++++++++++ include/config.h.w32 | 2 ++ kadmin/rpc.c | 3 ++- lib/asn1/gen_copy.c | 1 + lib/gssapi/krb5/init_sec_context.c | 1 + lib/hcrypto/libtommath/etc/tune.c | 3 ++- lib/hx509/cert.c | 2 ++ lib/hx509/cms.c | 1 + lib/hx509/file.c | 1 + lib/kafs/rxkad_kdf.c | 1 + lib/krb5/send_to_kdc.c | 2 ++ lib/roken/fnmatch.c | 1 + lib/roken/getuserinfo.c | 3 ++- lib/roken/snprintf.c | 1 + lib/roken/strftime.c | 1 + lib/roken/strptime.c | 1 + lib/wind/utf8.c | 7 +++++++ 17 files changed, 41 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index ce9c04c90..8c23a0a4e 100644 --- a/configure.ac +++ b/configure.ac @@ -504,6 +504,19 @@ rk_WIN32_EXPORT(BUILD_ROKEN_LIB, ROKEN_LIB) rk_WIN32_EXPORT(BUILD_GSSAPI_LIB, GSSAPI_LIB) rk_WIN32_EXPORT(BUILD_KDC_LIB, KDC_LIB) +dnl Deal with switch FALLTHROUGH +AH_TOP([ +#if defined(__GNUC__) +#if __GNUC__ >= 7 +# define fallthrough __attribute__((fallthrough)); +#else +# define fallthrough +#endif +#else +# define fallthrough +#endif +]) + dnl Checks for libraries. AC_FIND_FUNC_NO_LIBS(openpty, util,[ diff --git a/include/config.h.w32 b/include/config.h.w32 index e33e34705..f40a49261 100644 --- a/include/config.h.w32 +++ b/include/config.h.w32 @@ -32,6 +32,8 @@ #ifndef __CONFIG_H__ #define __CONFIG_H__ +#define fallthrough + #ifndef RCSID #define RCSID(msg) \ static const char *const rcsid[] = { (const char *)rcsid, "@(#)" msg } diff --git a/kadmin/rpc.c b/kadmin/rpc.c index 6ddb9dfa8..fcca391fd 100644 --- a/kadmin/rpc.c +++ b/kadmin/rpc.c @@ -972,7 +972,8 @@ process_stream(krb5_context contextp, INSIST(gctx.ctx == NULL); gctx.inprogress = 1; - /* FALLTHROUGH */ + fallthrough + /* FALLTHROUGH */ case RPG_CONTINUE_INIT: { gss_name_t src_name = GSS_C_NO_NAME; krb5_data in; diff --git a/lib/asn1/gen_copy.c b/lib/asn1/gen_copy.c index c1d963209..4c35d334c 100644 --- a/lib/asn1/gen_copy.c +++ b/lib/asn1/gen_copy.c @@ -62,6 +62,7 @@ copy_type (const char *from, const char *to, const Type *t, int preserve) copy_primitive ("heim_integer", from, to); break; } + fallthrough /* FALLTHROUGH */ case TBoolean: case TEnumerated : diff --git a/lib/gssapi/krb5/init_sec_context.c b/lib/gssapi/krb5/init_sec_context.c index d82fef8d3..8eb5b629b 100644 --- a/lib/gssapi/krb5/init_sec_context.c +++ b/lib/gssapi/krb5/init_sec_context.c @@ -929,6 +929,7 @@ OM_uint32 GSSAPI_CALLCONV _gsskrb5_init_sec_context time_rec); if (ret != GSS_S_COMPLETE) break; + fallthrough /* FALLTHROUGH */ case INITIATOR_RESTART: ret = init_auth_restart(minor_status, diff --git a/lib/hcrypto/libtommath/etc/tune.c b/lib/hcrypto/libtommath/etc/tune.c index bc2cdfe6e..098d0412f 100644 --- a/lib/hcrypto/libtommath/etc/tune.c +++ b/lib/hcrypto/libtommath/etc/tune.c @@ -424,7 +424,8 @@ int main(int argc, char **argv) break; case 'h': s_exit_code = EXIT_SUCCESS; - /* FALLTHROUGH */ + fallthrough + /* FALLTHROUGH */ default: s_usage(argv[0]); } diff --git a/lib/hx509/cert.c b/lib/hx509/cert.c index 0d99a748f..ec44e9108 100644 --- a/lib/hx509/cert.c +++ b/lib/hx509/cert.c @@ -2438,8 +2438,10 @@ hx509_verify_path(hx509_context context, * EE checking below. */ type = EE_CERT; + fallthrough /* FALLTHROUGH */ } + fallthrough } /* FALLTHROUGH */ case EE_CERT: diff --git a/lib/hx509/cms.c b/lib/hx509/cms.c index 453762bd1..30e4b4e34 100644 --- a/lib/hx509/cms.c +++ b/lib/hx509/cms.c @@ -182,6 +182,7 @@ fill_CMSIdentifier(const hx509_cert cert, &id->u.subjectKeyIdentifier); if (ret == 0) break; + fallthrough /* FALLTHROUGH */ case CMS_ID_NAME: { hx509_name name; diff --git a/lib/hx509/file.c b/lib/hx509/file.c index 1b5ca3eae..877fb1d48 100644 --- a/lib/hx509/file.c +++ b/lib/hx509/file.c @@ -230,6 +230,7 @@ hx509_pem_read(hx509_context context, where = INDATA; goto indata; } + fallthrough /* FALLTHROUGH */ case INHEADER: if (buf[0] == '\0') { diff --git a/lib/kafs/rxkad_kdf.c b/lib/kafs/rxkad_kdf.c index 88f499db3..351f6f87a 100644 --- a/lib/kafs/rxkad_kdf.c +++ b/lib/kafs/rxkad_kdf.c @@ -209,6 +209,7 @@ _kafs_derive_des_key(krb5_enctype enctype, void *keydata, size_t keylen, ret = compress_parity_bits(keydata, &keylen); if (ret) return ret; + fallthrough /* FALLTHROUGH */ default: if (enctype < 0) diff --git a/lib/krb5/send_to_kdc.c b/lib/krb5/send_to_kdc.c index 704b095b5..40118f053 100644 --- a/lib/krb5/send_to_kdc.c +++ b/lib/krb5/send_to_kdc.c @@ -1192,6 +1192,7 @@ krb5_sendto_context(krb5_context context, break; } action = KRB5_SENDTO_KRBHST; + fallthrough /* FALLTHROUGH */ case KRB5_SENDTO_KRBHST: if (ctx->krbhst == NULL) { @@ -1214,6 +1215,7 @@ krb5_sendto_context(krb5_context context, handle = heim_retain(ctx->krbhst); } action = KRB5_SENDTO_TIMEOUT; + fallthrough /* FALLTHROUGH */ case KRB5_SENDTO_TIMEOUT: diff --git a/lib/roken/fnmatch.c b/lib/roken/fnmatch.c index 7dfe49217..ff1b0dbd8 100644 --- a/lib/roken/fnmatch.c +++ b/lib/roken/fnmatch.c @@ -129,6 +129,7 @@ rk_fnmatch(const char *pattern, const char *string, int flags) --pattern; } } + fallthrough /* FALLTHROUGH */ default: if (c != *string++) diff --git a/lib/roken/getuserinfo.c b/lib/roken/getuserinfo.c index 5fc38e53a..b1bda23a2 100644 --- a/lib/roken/getuserinfo.c +++ b/lib/roken/getuserinfo.c @@ -136,7 +136,8 @@ roken_get_homedir(char *home, size_t homesz) } return home; } - /* Fallthru to return NULL */ + fallthrough + /* FALLTHROUGH */ #else #ifdef HAVE_GETPWNAM_R size_t buflen = 2048; diff --git a/lib/roken/snprintf.c b/lib/roken/snprintf.c index 620875f37..f1daa0f33 100644 --- a/lib/roken/snprintf.c +++ b/lib/roken/snprintf.c @@ -515,6 +515,7 @@ xyzprintf (struct snprintf_state *state, const char *char_format, va_list ap) } case '\0' : --format; + fallthrough /* FALLTHROUGH */ case '%' : (*state->append_char)(state, c); diff --git a/lib/roken/strftime.c b/lib/roken/strftime.c index 1dbc6fa9c..d2ba66972 100644 --- a/lib/roken/strftime.c +++ b/lib/roken/strftime.c @@ -377,6 +377,7 @@ strftime (char *buf, size_t maxsize, const char *format, break; case '\0' : --format; + fallthrough /* FALLTHROUGH */ case '%' : ret = snprintf (buf, maxsize - n, diff --git a/lib/roken/strptime.c b/lib/roken/strptime.c index 75c27a328..bb1b27d7c 100644 --- a/lib/roken/strptime.c +++ b/lib/roken/strptime.c @@ -424,6 +424,7 @@ strptime (const char *buf, const char *format, struct tm *timeptr) abort (); case '\0' : --format; + fallthrough /* FALLTHROUGH */ case '%' : if (*buf == '%') diff --git a/lib/wind/utf8.c b/lib/wind/utf8.c index d69db0c0c..1ab83a131 100644 --- a/lib/wind/utf8.c +++ b/lib/wind/utf8.c @@ -205,17 +205,21 @@ wind_ucs4utf8(const uint32_t *in, size_t in_len, char *out, size_t *out_len) case 4: out[3] = (ch | 0x80) & 0xbf; ch = ch >> 6; + fallthrough /* FALLTHROUGH */ case 3: out[2] = (ch | 0x80) & 0xbf; ch = ch >> 6; + fallthrough /* FALLTHROUGH */ case 2: out[1] = (ch | 0x80) & 0xbf; ch = ch >> 6; + fallthrough /* FALLTHROUGH */ case 1: out[0] = ch | first_char[len - 1]; + fallthrough /* FALLTHROUGH */ } } @@ -484,13 +488,16 @@ wind_ucs2utf8(const uint16_t *in, size_t in_len, char *out, size_t *out_len) case 3: out[2] = (ch | 0x80) & 0xbf; ch = ch >> 6; + fallthrough /* FALLTHROUGH */ case 2: out[1] = (ch | 0x80) & 0xbf; ch = ch >> 6; + fallthrough /* FALLTHROUGH */ case 1: out[0] = ch | first_char[len - 1]; + fallthrough /* FALLTHROUGH */ } out += len;