]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Move default action from after switch to within
authorChaoli Zhou <quic_zchaoli@quicinc.com>
Tue, 11 Oct 2022 10:57:44 +0000 (18:57 +0800)
committerJouni Malinen <j@w1.fi>
Fri, 14 Oct 2022 13:08:20 +0000 (16:08 +0300)
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 <quic_zchaoli@quicinc.com>
src/ap/ap_mlme.c
src/ap/ctrl_iface_ap.c
src/ap/fils_hlp.c
src/common/ieee802_11_common.c
src/common/sae.c
src/common/wpa_common.c
src/crypto/crypto_openssl.c
src/crypto/tls_openssl.c
src/drivers/driver_nl80211.c
src/drivers/netlink.c
wpa_supplicant/p2p_supplicant.c

index db8a26759c2868f4a925d47abaa47da8745529ce..309e69a3f95d79e4dd6f0b0031d5e2d45aa03ff7 100644 (file)
@@ -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 */
 
index ac8f6fae8df7d586cac9106c9059dad259d103b1..0df2327725c5c331538522c3a9944c723b309f20 100644 (file)
@@ -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 "?";
 }
 
 
index 0310aab52ec24a89efd841fc5f5e931b36db449e..d64fb8c402ac8eaf7d870188db0ca20855dc2e57 100644 (file)
@@ -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;
 }
 
 
index 1bc262a4cfd1ed0bda737dc193947bf5bf538787..d97525e9f9b86428e172f0ff90f2b6eca02a23fc 100644 (file)
@@ -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;
 }
 
 
index 33c7e5fe177f236ec19cb977c632b807da4f1d14..1e9ea8efa47f5752481be1af96f92759967b02ae 100644 (file)
@@ -603,9 +603,9 @@ static int sswu_curve_param(int group, int *z)
        case 30:
                *z = 7;
                return 0;
+       default:
+               return -1;
        }
-
-       return -1;
 }
 
 
index da707e66d3f40851222be8a9918de6ab42ef2b5a..8206ff078b8045bf10d5314e40a4a55ad18f2a4b 100644 (file)
@@ -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;
 }
 
 
index f058e067dfb438d1fc4502b4805804672898d7f5..2c591890a04eee894c505f058287241b9ec49b6c 100644 (file)
@@ -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;
 }
 
 
index 98787a3de0cda44ef9fc1901169452bab3291d63..bb916c5c08ccc17c33c7cba6ab272745d3e423d7 100644 (file)
@@ -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 "?";
 }
 
 
index 531699138e1dc03a796b4269199bf024b8eda503..ed9bf4841e021a3e6c518057aa926842c6e3a19d 100644 (file)
@@ -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;
 }
 
 
index 0e960f48c0ade6a00c5d1a000f0537ec7f2fbb7c..7780479c3e9133f5a527ac18239f43863e499b9c 100644 (file)
@@ -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 "?";
 }
 
 
index f6252b1aaa53fe4b1f2a5ac970038823adc96479..3971eb13434818fb5369c3a718ab87e2e9465812 100644 (file)
@@ -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;
 }