Use ARRAY_SIZE() macro

Replace the common sizeof(a)/sizeof(a[0]) constructions with a more
readable version.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-10-26 17:00:57 +03:00
parent 39044a7033
commit e7ecab4a3b
22 changed files with 51 additions and 56 deletions

View file

@ -358,7 +358,7 @@ static int acs_usable_ht40_chan(struct hostapd_channel_data *chan)
157, 184, 192 };
unsigned int i;
for (i = 0; i < sizeof(allowed) / sizeof(allowed[0]); i++)
for (i = 0; i < ARRAY_SIZE(allowed); i++)
if (chan->chan == allowed[i])
return 1;

View file

@ -74,11 +74,11 @@ static int dfs_is_chan_allowed(struct hostapd_channel_data *chan, int n_chans)
switch (n_chans) {
case 2:
allowed = allowed_40;
allowed_no = sizeof(allowed_40) / sizeof(allowed_40[0]);
allowed_no = ARRAY_SIZE(allowed_40);
break;
case 4:
allowed = allowed_80;
allowed_no = sizeof(allowed_80) / sizeof(allowed_80[0]);
allowed_no = ARRAY_SIZE(allowed_80);
break;
default:
wpa_printf(MSG_DEBUG, "Unknown width for %d channels", n_chans);

View file

@ -270,7 +270,7 @@ static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
first = sec_chan;
ok = 0;
for (k = 0; k < sizeof(allowed) / sizeof(allowed[0]); k++) {
for (k = 0; k < ARRAY_SIZE(allowed); k++) {
if (first == allowed[k]) {
ok = 1;
break;

View file

@ -1169,7 +1169,7 @@ static struct dh_group dh_groups[] = {
#endif /* ALL_DH_GROUPS */
};
#define NUM_DH_GROUPS (sizeof(dh_groups) / sizeof(dh_groups[0]))
#define NUM_DH_GROUPS ARRAY_SIZE(dh_groups)
const struct dh_group * dh_groups_get(int id)

View file

@ -182,7 +182,7 @@ set80211priv(struct madwifi_driver_data *drv, int op, void *data, int len)
#endif /* MADWIFI_NG */
int idx = op - first;
if (first <= op &&
idx < (int) (sizeof(opnames) / sizeof(opnames[0])) &&
idx < (int) ARRAY_SIZE(opnames) &&
opnames[idx])
perror(opnames[idx]);
else

View file

@ -3967,7 +3967,7 @@ static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
"handle %p", bss->nl_mgmt);
for (i = 0; i < sizeof(stypes) / sizeof(stypes[0]); i++) {
for (i = 0; i < ARRAY_SIZE(stypes); i++) {
if (nl80211_register_frame(bss, bss->nl_mgmt,
(WLAN_FC_TYPE_MGMT << 2) |
(stypes[i] << 4),
@ -7238,7 +7238,7 @@ static struct sock_filter msock_filter_insns[] = {
};
static struct sock_fprog msock_filter = {
.len = sizeof(msock_filter_insns)/sizeof(msock_filter_insns[0]),
.len = ARRAY_SIZE(msock_filter_insns),
.filter = msock_filter_insns,
};

View file

@ -21,7 +21,7 @@ static struct ikev2_integ_alg ikev2_integ_algs[] = {
{ AUTH_HMAC_MD5_96, 16, 12 }
};
#define NUM_INTEG_ALGS (sizeof(ikev2_integ_algs) / sizeof(ikev2_integ_algs[0]))
#define NUM_INTEG_ALGS ARRAY_SIZE(ikev2_integ_algs)
static struct ikev2_prf_alg ikev2_prf_algs[] = {
@ -29,7 +29,7 @@ static struct ikev2_prf_alg ikev2_prf_algs[] = {
{ PRF_HMAC_MD5, 16, 16 }
};
#define NUM_PRF_ALGS (sizeof(ikev2_prf_algs) / sizeof(ikev2_prf_algs[0]))
#define NUM_PRF_ALGS ARRAY_SIZE(ikev2_prf_algs)
static struct ikev2_encr_alg ikev2_encr_algs[] = {
@ -37,7 +37,7 @@ static struct ikev2_encr_alg ikev2_encr_algs[] = {
{ ENCR_3DES, 24, 8 }
};
#define NUM_ENCR_ALGS (sizeof(ikev2_encr_algs) / sizeof(ikev2_encr_algs[0]))
#define NUM_ENCR_ALGS ARRAY_SIZE(ikev2_encr_algs)
const struct ikev2_integ_alg * ikev2_get_integ(int id)

View file

@ -233,7 +233,7 @@ static struct radius_attr_type radius_attrs[] =
{ RADIUS_ATTR_NAS_IPV6_ADDRESS, "NAS-IPv6-Address", RADIUS_ATTR_IPV6 },
{ RADIUS_ATTR_ERROR_CAUSE, "Error-Cause", RADIUS_ATTR_INT32 }
};
#define RADIUS_ATTRS (sizeof(radius_attrs) / sizeof(radius_attrs[0]))
#define RADIUS_ATTRS ARRAY_SIZE(radius_attrs)
static struct radius_attr_type *radius_get_attr_type(u8 type)

View file

@ -57,8 +57,7 @@ static const struct tls_cipher_suite tls_cipher_suites[] = {
TLS_CIPHER_AES_256_CBC, TLS_HASH_SHA256 }
};
#define NUM_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
#define NUM_TLS_CIPHER_SUITES NUM_ELEMS(tls_cipher_suites)
#define NUM_TLS_CIPHER_SUITES ARRAY_SIZE(tls_cipher_suites)
static const struct tls_cipher_data tls_ciphers[] = {
@ -84,7 +83,7 @@ static const struct tls_cipher_data tls_ciphers[] = {
CRYPTO_CIPHER_ALG_AES }
};
#define NUM_TLS_CIPHER_DATA NUM_ELEMS(tls_ciphers)
#define NUM_TLS_CIPHER_DATA ARRAY_SIZE(tls_ciphers)
/**

View file

@ -268,7 +268,7 @@ int os_program_init(void)
struct __user_cap_header_struct header;
struct __user_cap_data_struct cap;
setgroups(sizeof(groups)/sizeof(groups[0]), groups);
setgroups(ARRAY_SIZE(groups), groups);
prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);