From 9cee9b3c08bb15e6de78836cbec062fdc6506902 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 25 Aug 2023 11:26:08 +0200 Subject: [PATCH] [c standard] use WINPR_FALLTHROUGH use the macro to silence intentional switch fallthrough locations --- .../urbdrc/client/libusb/libusb_udevice.c | 5 ++- client/X11/xf_input.c | 6 ++++ libfreerdp/core/credssp_auth.c | 3 +- libfreerdp/core/gateway/rpc_client.c | 3 +- winpr/include/config/wtypes.h.in | 10 ++++-- winpr/libwinpr/crt/unicode_builtin.c | 31 ++++++++++++++++++- winpr/libwinpr/ncrypt/ncrypt_pkcs11.c | 5 ++- winpr/libwinpr/sspi/Kerberos/kerberos.c | 1 + winpr/libwinpr/sspi/Negotiate/negotiate.c | 5 ++- 9 files changed, 60 insertions(+), 9 deletions(-) diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index 9f7bc1886..ff37b039e 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -286,10 +287,12 @@ static void LIBUSB_CALL func_iso_callback(struct libusb_transfer* transfer) } } /* fallthrough */ - + WINPR_FALLTHROUGH case LIBUSB_TRANSFER_CANCELLED: + /* fallthrough */ WINPR_FALLTHROUGH case LIBUSB_TRANSFER_TIMED_OUT: + /* fallthrough */ WINPR_FALLTHROUGH case LIBUSB_TRANSFER_ERROR: { diff --git a/client/X11/xf_input.c b/client/X11/xf_input.c index 827c7b7a8..1d9894274 100644 --- a/client/X11/xf_input.c +++ b/client/X11/xf_input.c @@ -38,6 +38,7 @@ #include "xf_input.h" #include +#include #include #define TAG CLIENT_TAG("x11") @@ -855,15 +856,19 @@ static int xf_input_handle_event_remote(xfContext* xfc, const XEvent* event) { case XI_TouchBegin: xf_input_pens_unhover(xfc); + /* fallthrough */ WINPR_FALLTHROUGH case XI_TouchUpdate: + /* fallthrough */ WINPR_FALLTHROUGH case XI_TouchEnd: xf_input_touch_remote(xfc, cookie.cc->data, cookie.cc->evtype); break; case XI_ButtonPress: + /* fallthrough */ WINPR_FALLTHROUGH case XI_Motion: + /* fallthrough */ WINPR_FALLTHROUGH case XI_ButtonRelease: { @@ -877,6 +882,7 @@ static int xf_input_handle_event_remote(xfContext* xfc, const XEvent* event) break; } } + /* fallthrough */ WINPR_FALLTHROUGH default: xf_input_pens_unhover(xfc); diff --git a/libfreerdp/core/credssp_auth.c b/libfreerdp/core/credssp_auth.c index 47e80b08e..409812b3d 100644 --- a/libfreerdp/core/credssp_auth.c +++ b/libfreerdp/core/credssp_auth.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -706,7 +707,7 @@ void credssp_auth_free(rdpCredsspAuth* auth) case AUTH_STATE_FINAL: WINPR_ASSERT(auth->table->DeleteSecurityContext); auth->table->DeleteSecurityContext(&auth->context); - /* FALLTHROUGH */ + /* fallthrouth */ WINPR_FALLTHROUGH case AUTH_STATE_CREDS: WINPR_ASSERT(auth->table->FreeCredentialsHandle); diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index abee07832..9166e59db 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -286,7 +287,7 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) WLog_ERR(TAG, "rpc_secure_bind: error sending rpc_auth_3 pdu!"); return -1; } - /* FALLTHROUGH */ + /* fallthrough */ WINPR_FALLTHROUGH case RPC_BIND_STATE_COMPLETE: rpc_client_transition_to_state(rpc, RPC_CLIENT_STATE_CONTEXT_NEGOTIATED); diff --git a/winpr/include/config/wtypes.h.in b/winpr/include/config/wtypes.h.in index 4cdf1d948..1f0b41201 100644 --- a/winpr/include/config/wtypes.h.in +++ b/winpr/include/config/wtypes.h.in @@ -29,9 +29,13 @@ #define WINPR_RESTRICT #endif -// C17 related macros -#if defined(__STDC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201710L) -#define WINPR_FALLTHROUGH [[fallthrough]] +// C23 related macros +#if defined(__STDC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) +#define WINPR_FALLTHROUGH [[fallthrough]]; +#elif defined(__clang__) +#define WINPR_FALLTHROUGH __attribute__((fallthrough)); +#elif defined(__GNUC__) && (__GNUC__ >= 7) +#define WINPR_FALLTHROUGH __attribute__((fallthrough)); #else #define WINPR_FALLTHROUGH #endif diff --git a/winpr/libwinpr/crt/unicode_builtin.c b/winpr/libwinpr/crt/unicode_builtin.c index 861f915b7..531a84d82 100644 --- a/winpr/libwinpr/crt/unicode_builtin.c +++ b/winpr/libwinpr/crt/unicode_builtin.c @@ -38,6 +38,7 @@ See the header file "utf.h" for complete documentation. ------------------------------------------------------------------------ */ +#include #include #include @@ -242,14 +243,19 @@ static ConversionResult winpr_ConvertUTF16toUTF8_Internal(const uint16_t** sourc case 4: *--target = (uint8_t)((ch | byteMark) & byteMask); ch >>= 6; - + /* fallthrough */ + WINPR_FALLTHROUGH case 3: *--target = (uint8_t)((ch | byteMark) & byteMask); ch >>= 6; + /* fallthrough */ + WINPR_FALLTHROUGH case 2: *--target = (uint8_t)((ch | byteMark) & byteMask); ch >>= 6; + /* fallthrough */ + WINPR_FALLTHROUGH case 1: *--target = (uint8_t)(ch | firstByteMark[bytesToWrite]); @@ -262,12 +268,18 @@ static ConversionResult winpr_ConvertUTF16toUTF8_Internal(const uint16_t** sourc /* note: everything falls through. */ case 4: --target; + /* fallthrough */ + WINPR_FALLTHROUGH case 3: --target; + /* fallthrough */ + WINPR_FALLTHROUGH case 2: --target; + /* fallthrough */ + WINPR_FALLTHROUGH case 1: --target; @@ -309,10 +321,14 @@ static bool isLegalUTF8(const uint8_t* source, int length) case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; + /* fallthrough */ + WINPR_FALLTHROUGH case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; + /* fallthrough */ + WINPR_FALLTHROUGH case 2: if ((a = (*--srcptr)) > 0xBF) @@ -348,7 +364,10 @@ static bool isLegalUTF8(const uint8_t* source, int length) default: if (a < 0x80) return false; + break; } + /* fallthrough */ + WINPR_FALLTHROUGH case 1: if (*source >= 0x80 && *source < 0xC2) @@ -404,22 +423,32 @@ static ConversionResult winpr_ConvertUTF8toUTF16_Internal(const uint8_t** source case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ + /* fallthrough */ + WINPR_FALLTHROUGH case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ + /* fallthrough */ + WINPR_FALLTHROUGH case 3: ch += *source++; ch <<= 6; + /* fallthrough */ + WINPR_FALLTHROUGH case 2: ch += *source++; ch <<= 6; + /* fallthrough */ + WINPR_FALLTHROUGH case 1: ch += *source++; ch <<= 6; + /* fallthrough */ + WINPR_FALLTHROUGH case 0: ch += *source++; diff --git a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c index f912b27de..f75304acf 100644 --- a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c +++ b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c @@ -208,9 +208,12 @@ static CK_RV object_load_attributes(NCryptP11ProviderHandle* provider, CK_SESSIO return rv; /* fallthrough */ WINPR_FALLTHROUGH - case CKR_ATTRIBUTE_SENSITIVE: + /* fallthrough */ + WINPR_FALLTHROUGH case CKR_ATTRIBUTE_TYPE_INVALID: + /* fallthrough */ + WINPR_FALLTHROUGH case CKR_BUFFER_TOO_SMALL: /* attributes need some buffers for the result value */ if (!attributes_allocate_buffers(attributes, count)) diff --git a/winpr/libwinpr/sspi/Kerberos/kerberos.c b/winpr/libwinpr/sspi/Kerberos/kerberos.c index cbd3ee676..36ad147e6 100644 --- a/winpr/libwinpr/sspi/Kerberos/kerberos.c +++ b/winpr/libwinpr/sspi/Kerberos/kerberos.c @@ -818,6 +818,7 @@ static SECURITY_STATUS SEC_ENTRY kerberos_InitializeSecurityContextA( goto bad_token; /* Continue to AP-REQ */ + /* fall through */ WINPR_FALLTHROUGH case KERBEROS_STATE_AP_REQ: diff --git a/winpr/libwinpr/sspi/Negotiate/negotiate.c b/winpr/libwinpr/sspi/Negotiate/negotiate.c index 682487b65..b6c2797e4 100644 --- a/winpr/libwinpr/sspi/Negotiate/negotiate.c +++ b/winpr/libwinpr/sspi/Negotiate/negotiate.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -798,7 +799,9 @@ static SECURITY_STATUS SEC_ENTRY negotiate_InitializeSecurityContextW( case REJECT: return SEC_E_LOGON_DENIED; case REQUEST_MIC: - context->mic = TRUE; /* fallthrough */ + context->mic = TRUE; + /* fallthrough */ + WINPR_FALLTHROUGH case ACCEPT_INCOMPLETE: context->state = NEGOTIATE_STATE_NEGORESP; break;