dns: Use LWIP_ARRAYSIZE instead of open coded

Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
Axel Lin 2016-05-11 16:24:50 +08:00 committed by Dirk Ziegelmeier
parent 7e9377a9c7
commit 8c0f620d83

View File

@ -463,7 +463,7 @@ dns_init_local(void)
/* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */ /* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */
struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT; struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
size_t namelen; size_t namelen;
for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) { for (i = 0; i < LWIP_ARRAYSIZE(local_hostlist_init); i++) {
struct local_hostlist_entry *init_entry = &local_hostlist_init[i]; struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL); LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL);
namelen = strlen(init_entry->name); namelen = strlen(init_entry->name);
@ -508,7 +508,7 @@ dns_lookup_local(const char *hostname, ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(u8_
} }
#else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ #else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
size_t i; size_t i;
for (i = 0; i < sizeof(local_hostlist_static) / sizeof(struct local_hostlist_entry); i++) { for (i = 0; i < LWIP_ARRAYSIZE(local_hostlist_static); i++) {
if ((LWIP_DNS_STRICMP(local_hostlist_static[i].name, hostname) == 0) && if ((LWIP_DNS_STRICMP(local_hostlist_static[i].name, hostname) == 0) &&
LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, local_hostlist_static[i].addr)) { LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, local_hostlist_static[i].addr)) {
if (addr) { if (addr) {