PPP: Use LWIP_ARRAYSIZE at appropriate places

Use LWIP_ARRAYSIZE to simplify the code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Reviewed-by: Sylvain Rochet <gradator@gradator.net>
[Sylvain Rochet <gradator@gradator.net>: added missing casts]
Signed-off-by: Sylvain Rochet <gradator@gradator.net>
This commit is contained in:
Axel Lin 2016-05-12 23:07:59 +02:00 committed by Sylvain Rochet
parent 8c0f620d83
commit ab989c3551
7 changed files with 10 additions and 14 deletions

View File

@ -1533,8 +1533,7 @@ static int ccp_printpkt(const u_char *p, int plen, void (*printer) (void *, cons
if (len < HEADERLEN || len > plen)
return 0;
if (code >= 1 && code <= (int)(sizeof(ccp_codenames) / sizeof(char *))
&& ccp_codenames[code-1] != NULL)
if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(ccp_codenames) && ccp_codenames[code-1] != NULL)
printer(arg, " %s", ccp_codenames[code-1]);
else
printer(arg, " code=0x%x", code);

View File

@ -604,7 +604,7 @@ static int chap_print_pkt(const unsigned char *p, int plen,
if (len < CHAP_HDRLEN || len > plen)
return 0;
if (code >= 1 && code <= (int)sizeof(chap_code_names) / (int)sizeof(char *))
if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(chap_code_names))
printer(arg, " %s", chap_code_names[code-1]);
else
printer(arg, " code=0x%x", code);

View File

@ -2146,7 +2146,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c
if (len < EAP_HEADERLEN || len > inlen)
return (0);
if (code >= 1 && code <= (int)sizeof(eap_codenames) / (int)sizeof(char *))
if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(eap_codenames))
printer(arg, " %s", eap_codenames[code-1]);
else
printer(arg, " code=0x%x", code);
@ -2160,8 +2160,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c
}
GETCHAR(rtype, inp);
len--;
if (rtype >= 1 &&
rtype <= (int)sizeof (eap_typenames) / (int)sizeof (char *))
if (rtype >= 1 && rtype <= (int)LWIP_ARRAYSIZE(eap_typenames))
printer(arg, " %s", eap_typenames[rtype-1]);
else
printer(arg, " type=0x%x", rtype);
@ -2299,8 +2298,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c
break;
GETCHAR(rtype, inp);
len--;
if (rtype >= 1 &&
rtype <= (int)sizeof (eap_typenames) / (int)sizeof (char *))
if (rtype >= 1 && rtype <= (int)LWIP_ARRAYSIZE(eap_typenames))
printer(arg, " %s", eap_typenames[rtype-1]);
else
printer(arg, " type=0x%x", rtype);
@ -2323,8 +2321,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c
GETCHAR(rtype, inp);
len--;
printer(arg, " <Suggested-type %02X", rtype);
if (rtype >= 1 &&
rtype < (int)sizeof (eap_typenames) / (int)sizeof (char *))
if (rtype >= 1 && rtype < (int)LWIP_ARRAYSIZE(eap_typenames))
printer(arg, " (%s)", eap_typenames[rtype-1]);
printer(arg, ">");
break;

View File

@ -2244,7 +2244,7 @@ static int ipcp_printpkt(const u_char *p, int plen,
if (len < HEADERLEN || len > plen)
return 0;
if (code >= 1 && code <= (int)sizeof(ipcp_codenames) / (int)sizeof(char *))
if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(ipcp_codenames))
printer(arg, " %s", ipcp_codenames[code-1]);
else
printer(arg, " code=0x%x", code);

View File

@ -1416,7 +1416,7 @@ static int ipv6cp_printpkt(const u_char *p, int plen,
if (len < HEADERLEN || len > plen)
return 0;
if (code >= 1 && code <= (int)sizeof(ipv6cp_codenames) / (int)sizeof(char *))
if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(ipv6cp_codenames))
printer(arg, " %s", ipv6cp_codenames[code-1]);
else
printer(arg, " code=0x%x", code);

View File

@ -2393,7 +2393,7 @@ static int lcp_printpkt(const u_char *p, int plen,
if (len < HEADERLEN || len > plen)
return 0;
if (code >= 1 && code <= (int)sizeof(lcp_codenames) / (int)sizeof(char *))
if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(lcp_codenames))
printer(arg, " %s", lcp_codenames[code-1]);
else
printer(arg, " code=0x%x", code);

View File

@ -614,7 +614,7 @@ static int upap_printpkt(const u_char *p, int plen, void (*printer) (void *, con
if (len < UPAP_HEADERLEN || len > plen)
return 0;
if (code >= 1 && code <= (int)sizeof(upap_codenames) / (int)sizeof(char *))
if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(upap_codenames))
printer(arg, " %s", upap_codenames[code-1]);
else
printer(arg, " code=0x%x", code);