From b572774c709c6d6cedecf3937eddb78df05edfa7 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Sat, 17 Jul 2021 08:24:46 +0200 Subject: [PATCH] Fix Linux kernel coding style warning Prefer ARRAY_SIZE(...) Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> --- gnutls-dtls.c | 6 +++--- http-auth.c | 12 ++++++------ http.c | 2 +- openconnect-internal.h | 2 ++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gnutls-dtls.c b/gnutls-dtls.c index d8110b4b..3fd78e95 100644 --- a/gnutls-dtls.c +++ b/gnutls-dtls.c @@ -102,7 +102,7 @@ void gather_dtls_ciphers(struct openconnect_info *vpninfo, struct oc_text_buf *b { int i, first = 1; - for (i = 0; i < sizeof(gnutls_dtls_ciphers) / sizeof(gnutls_dtls_ciphers[0]); i++) { + for (i = 0; i < ARRAY_SIZE(gnutls_dtls_ciphers); i++) { if (!gnutls_dtls_ciphers[i].cisco_dtls12 && gnutls_check_version(gnutls_dtls_ciphers[i].min_gnutls_version)) { buf_append(buf, "%s%s", first ? "" : ":", @@ -140,7 +140,7 @@ void gather_dtls_ciphers(struct openconnect_info *vpninfo, struct oc_text_buf *b break; if (gnutls_cipher_suite_info(idx, NULL, NULL, &cipher, &mac, NULL) != NULL) { - for (i = 0; i < sizeof(gnutls_dtls_ciphers)/sizeof(gnutls_dtls_ciphers[0]); i++) { + for (i = 0; i < ARRAY_SIZE(gnutls_dtls_ciphers); i++) { if (used & (1 << i)) continue; if (gnutls_dtls_ciphers[i].mac == mac && gnutls_dtls_ciphers[i].cipher == cipher) { @@ -284,7 +284,7 @@ static int start_dtls_resume_handshake(struct openconnect_info *vpninfo, gnutls_ int err; int cipher; - for (cipher = 0; cipher < sizeof(gnutls_dtls_ciphers)/sizeof(gnutls_dtls_ciphers[0]); cipher++) { + for (cipher = 0; cipher < ARRAY_SIZE(gnutls_dtls_ciphers); cipher++) { if (gnutls_dtls_ciphers[cipher].cisco_dtls12 != vpninfo->dtls12 || gnutls_check_version(gnutls_dtls_ciphers[cipher].min_gnutls_version) == NULL) continue; diff --git a/http-auth.c b/http-auth.c index cf263f5b..219a3743 100644 --- a/http-auth.c +++ b/http-auth.c @@ -140,7 +140,7 @@ int gen_authorization_hdr(struct openconnect_info *vpninfo, int proxy, int ret; int i; - for (i = 0; i < sizeof(auth_methods) / sizeof(auth_methods[0]); i++) { + for (i = 0; i < ARRAY_SIZE(auth_methods); i++) { struct http_auth_state *auth_state; if (proxy) auth_state = &vpninfo->proxy_auth[auth_methods[i].state_index]; @@ -218,7 +218,7 @@ int proxy_auth_hdrs(struct openconnect_info *vpninfo, char *hdr, char *val) if (strcasecmp(hdr, "Proxy-Authenticate")) return 0; - for (i = 0; i < sizeof(auth_methods) / sizeof(auth_methods[0]); i++) { + for (i = 0; i < ARRAY_SIZE(auth_methods); i++) { /* Return once we've found a match */ if (handle_auth_proto(vpninfo, vpninfo->proxy_auth, &auth_methods[i], val)) return 0; @@ -240,7 +240,7 @@ int http_auth_hdrs(struct openconnect_info *vpninfo, char *hdr, char *val) if (strcasecmp(hdr, "WWW-Authenticate")) return 0; - for (i = 0; i < sizeof(auth_methods) / sizeof(auth_methods[0]); i++) { + for (i = 0; i < ARRAY_SIZE(auth_methods); i++) { /* Return once we've found a match */ if (handle_auth_proto(vpninfo, vpninfo->http_auth, &auth_methods[i], val)) return 0; @@ -254,7 +254,7 @@ void clear_auth_states(struct openconnect_info *vpninfo, { int i; - for (i = 0; i < sizeof(auth_methods) / sizeof(auth_methods[0]); i++) { + for (i = 0; i < ARRAY_SIZE(auth_methods); i++) { struct http_auth_state *auth = &auth_states[auth_methods[i].state_index]; /* The 'reset' argument is set when we're connected successfully, @@ -280,7 +280,7 @@ static int set_authmethods(struct openconnect_info *vpninfo, struct http_auth_st int i, len; const char *p; - for (i = 0; i < sizeof(auth_methods) / sizeof(auth_methods[0]); i++) + for (i = 0; i < ARRAY_SIZE(auth_methods); i++) auth_states[auth_methods[i].state_index].state = AUTH_DISABLED; while (methods) { @@ -291,7 +291,7 @@ static int set_authmethods(struct openconnect_info *vpninfo, struct http_auth_st } else len = strlen(methods); - for (i = 0; i < sizeof(auth_methods) / sizeof(auth_methods[0]); i++) { + for (i = 0; i < ARRAY_SIZE(auth_methods); i++) { if (strprefix_match(methods, len, auth_methods[i].name) || (auth_methods[i].state_index == AUTH_TYPE_GSSAPI && strprefix_match(methods, len, "gssapi"))) { diff --git a/http.c b/http.c index d4994347..1ae60f33 100644 --- a/http.c +++ b/http.c @@ -1194,7 +1194,7 @@ static int process_socks_proxy(struct openconnect_info *vpninfo) } if (buf[1]) { unsigned char err = buf[1]; - if (err < sizeof(socks_errors) / sizeof(socks_errors[0])) + if (err < ARRAY_SIZE(socks_errors)) vpn_progress(vpninfo, PRG_ERR, _("SOCKS proxy error %02x: %s\n"), err, _(socks_errors[err])); diff --git a/openconnect-internal.h b/openconnect-internal.h index 91610d41..56cfbc7f 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -165,6 +165,8 @@ struct oc_vring { #endif +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + /****************************************************************************/ -- 2.50.1