From: Chaoli Zhou Date: Tue, 11 Oct 2022 10:57:44 +0000 (+0800) Subject: Move default action from after switch to within X-Git-Tag: hostap_2_11~1656 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8a05de6697d6fe0808aa1d9f209d887005d3ba1;p=thirdparty%2Fhostap.git Move default action from after switch to within Move from this type of constructions: switch (val) { case 1: something; break; } default-action; into following: switch (val) { case 1: something; break; default: default-action; break } for cases where the switch statement is not expected to contain a full set of enum values and as such, does not lose value from not having the default target. This makes the intent of default behavior clearer for static analyzers like gcc with -Wswitch-default. Signed-off-by: Chaoli Zhou --- diff --git a/src/ap/ap_mlme.c b/src/ap/ap_mlme.c index db8a26759..309e69a3f 100644 --- a/src/ap/ap_mlme.c +++ b/src/ap/ap_mlme.c @@ -29,9 +29,9 @@ static const char * mlme_auth_alg_str(int alg) return "SHARED_KEY"; case WLAN_AUTH_FT: return "FT"; + default: + return "unknown"; } - - return "unknown"; } #endif /* CONFIG_NO_HOSTAPD_LOGGER */ diff --git a/src/ap/ctrl_iface_ap.c b/src/ap/ctrl_iface_ap.c index ac8f6fae8..0df232772 100644 --- a/src/ap/ctrl_iface_ap.c +++ b/src/ap/ctrl_iface_ap.c @@ -206,9 +206,9 @@ static const char * timeout_next_str(int val) return "REMOVE"; case STA_DISASSOC_FROM_CLI: return "DISASSOC_FROM_CLI"; + default: + return "?"; } - - return "?"; } diff --git a/src/ap/fils_hlp.c b/src/ap/fils_hlp.c index 0310aab52..d64fb8c40 100644 --- a/src/ap/fils_hlp.c +++ b/src/ap/fils_hlp.c @@ -530,9 +530,9 @@ static int fils_process_hlp_ip(struct hostapd_data *hapd, switch (iph->ip_p) { case 17: return fils_process_hlp_udp(hapd, sta, dst, pos, len); + default: + return 0; } - - return 0; } @@ -567,9 +567,9 @@ static int fils_process_hlp_req(struct hostapd_data *hapd, case ETH_P_IP: return fils_process_hlp_ip(hapd, sta, pos, pkt + 2, end - pkt - 2); + default: + return 0; } - - return 0; } diff --git a/src/common/ieee802_11_common.c b/src/common/ieee802_11_common.c index 1bc262a4c..d97525e9f 100644 --- a/src/common/ieee802_11_common.c +++ b/src/common/ieee802_11_common.c @@ -1263,8 +1263,9 @@ static int ieee80211_chan_to_freq_us(u8 op_class, u8 chan) if (chan < 25 || chan > 29) return -1; return 56160 + 2160 * (chan - 24); + default: + return -1; } - return -1; } @@ -1313,8 +1314,9 @@ static int ieee80211_chan_to_freq_eu(u8 op_class, u8 chan) if (chan != 25) return -1; return 56160 + 2160 * (chan - 24); + default: + return -1; } - return -1; } @@ -1369,8 +1371,9 @@ static int ieee80211_chan_to_freq_jp(u8 op_class, u8 chan) if (chan != 25) return -1; return 56160 + 2160 * (chan - 24); + default: + return -1; } - return -1; } @@ -1395,8 +1398,9 @@ static int ieee80211_chan_to_freq_cn(u8 op_class, u8 chan) if (chan < 149 || chan > 165) return -1; return 5000 + 5 * chan; + default: + return -1; } - return -1; } @@ -1482,8 +1486,9 @@ static int ieee80211_chan_to_freq_global(u8 op_class, u8 chan) if (chan < 25 || chan > 29) return -1; return 56160 + 2160 * (chan - 24); + default: + return -1; } - return -1; } /** @@ -2613,9 +2618,9 @@ int op_class_to_bandwidth(u8 op_class) return 6480; case 183: /* 60 GHz band, EDMG CB4, channel 25..29 */ return 8640; + default: + return 20; } - - return 20; } @@ -2677,8 +2682,9 @@ enum oper_chan_width op_class_to_ch_width(u8 op_class) return CONF_OPER_CHWIDTH_6480MHZ; case 183: /* 60 GHz band, EDMG CB4, channel 25..29 */ return CONF_OPER_CHWIDTH_8640MHZ; + default: + return CONF_OPER_CHWIDTH_USE_HT; } - return CONF_OPER_CHWIDTH_USE_HT; } diff --git a/src/common/sae.c b/src/common/sae.c index 33c7e5fe1..1e9ea8efa 100644 --- a/src/common/sae.c +++ b/src/common/sae.c @@ -603,9 +603,9 @@ static int sswu_curve_param(int group, int *z) case 30: *z = 7; return 0; + default: + return -1; } - - return -1; } diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c index da707e66d..8206ff078 100644 --- a/src/common/wpa_common.c +++ b/src/common/wpa_common.c @@ -2736,9 +2736,9 @@ int wpa_cipher_key_len(int cipher) return 16; case WPA_CIPHER_TKIP: return 32; + default: + return 0; } - - return 0; } @@ -2751,9 +2751,9 @@ int wpa_cipher_rsc_len(int cipher) case WPA_CIPHER_GCMP: case WPA_CIPHER_TKIP: return 6; + default: + return 0; } - - return 0; } @@ -2778,8 +2778,9 @@ enum wpa_alg wpa_cipher_to_alg(int cipher) return WPA_ALG_BIP_GMAC_256; case WPA_CIPHER_BIP_CMAC_256: return WPA_ALG_BIP_CMAC_256; + default: + return WPA_ALG_NONE; } - return WPA_ALG_NONE; } diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c index f058e067d..2c591890a 100644 --- a/src/crypto/crypto_openssl.c +++ b/src/crypto/crypto_openssl.c @@ -454,9 +454,9 @@ static const EVP_CIPHER * aes_get_evp_cipher(size_t keylen) return EVP_aes_192_ecb(); case 32: return EVP_aes_256_ecb(); + default: + return NULL; } - - return NULL; } @@ -4090,10 +4090,12 @@ int crypto_ec_key_group(struct crypto_ec_key *key) case NID_brainpoolP512r1: return 30; #endif /* NID_brainpoolP512r1 */ + default: + wpa_printf(MSG_ERROR, + "OpenSSL: Unsupported curve (nid=%d) in EC key", + nid); + return -1; } - wpa_printf(MSG_ERROR, "OpenSSL: Unsupported curve (nid=%d) in EC key", - nid); - return -1; } diff --git a/src/crypto/tls_openssl.c b/src/crypto/tls_openssl.c index 98787a3de..bb916c5c0 100644 --- a/src/crypto/tls_openssl.c +++ b/src/crypto/tls_openssl.c @@ -5551,8 +5551,9 @@ static const char * openssl_pkey_type_str(const EVP_PKEY *pkey) return "DH"; case EVP_PKEY_EC: return "EC"; + default: + return "?"; } - return "?"; } diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 531699138..ed9bf4841 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -219,8 +219,9 @@ enum chan_width convert2width(int width) return CHAN_WIDTH_160; case NL80211_CHAN_WIDTH_320: return CHAN_WIDTH_320; + default: + return CHAN_WIDTH_UNKNOWN; } - return CHAN_WIDTH_UNKNOWN; } @@ -3189,9 +3190,9 @@ static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) return RSN_CIPHER_SUITE_WEP40; case WPA_CIPHER_GTK_NOT_USED: return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; + default: + return 0; } - - return 0; } diff --git a/src/drivers/netlink.c b/src/drivers/netlink.c index 0e960f48c..7780479c3 100644 --- a/src/drivers/netlink.c +++ b/src/drivers/netlink.c @@ -147,8 +147,9 @@ static const char * linkmode_str(int mode) return "kernel-control"; case 1: return "userspace-control"; + default: + return "?"; } - return "?"; } @@ -161,8 +162,9 @@ static const char * operstate_str(int state) return "IF_OPER_DORMANT"; case IF_OPER_UP: return "IF_OPER_UP"; + default: + return "?"; } - return "?"; } diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index f6252b1aa..3971eb134 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -530,9 +530,9 @@ static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface) return WPA_IF_P2P_GO; case P2P_GROUP_INTERFACE_CLIENT: return WPA_IF_P2P_CLIENT; + default: + return WPA_IF_P2P_GROUP; } - - return WPA_IF_P2P_GROUP; }