From 02d34c8c4c4759cf9282714113756453e38d96f8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 18 Dec 2016 22:14:26 +0900 Subject: [PATCH] nghttpx: Fix dead code found by coverity scan --- src/shrpx_dns_resolver.cc | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/shrpx_dns_resolver.cc b/src/shrpx_dns_resolver.cc index 104ba633..90c07a2f 100644 --- a/src/shrpx_dns_resolver.cc +++ b/src/shrpx_dns_resolver.cc @@ -293,32 +293,29 @@ void DNSResolver::on_result(int status, hostent *hostent) { return; } + auto ap = *hostent->h_addr_list; + assert(ap); + switch (hostent->h_addrtype) { case AF_INET: - for (auto ap = hostent->h_addr_list; *ap; ++ap) { - status_ = DNS_STATUS_OK; - result_.len = sizeof(result_.su.in); - result_.su.in = {}; - result_.su.in.sin_family = AF_INET; + status_ = DNS_STATUS_OK; + result_.len = sizeof(result_.su.in); + result_.su.in = {}; + result_.su.in.sin_family = AF_INET; #ifdef HAVE_SOCKADDR_IN_SIN_LEN - result_.su.in.sin_len = sizeof(result_.su.in); + result_.su.in.sin_len = sizeof(result_.su.in); #endif // HAVE_SOCKADDR_IN_SIN_LEN - memcpy(&result_.su.in.sin_addr, *ap, sizeof(result_.su.in.sin_addr)); - break; - } + memcpy(&result_.su.in.sin_addr, ap, sizeof(result_.su.in.sin_addr)); break; case AF_INET6: - for (auto ap = hostent->h_addr_list; *ap; ++ap) { - status_ = DNS_STATUS_OK; - result_.len = sizeof(result_.su.in6); - result_.su.in6 = {}; - result_.su.in6.sin6_family = AF_INET6; + status_ = DNS_STATUS_OK; + result_.len = sizeof(result_.su.in6); + result_.su.in6 = {}; + result_.su.in6.sin6_family = AF_INET6; #ifdef HAVE_SOCKADDR_IN6_SIN6_LEN - result_.su.in6.sin6_len = sizeof(result_.su.in6); + result_.su.in6.sin6_len = sizeof(result_.su.in6); #endif // HAVE_SOCKADDR_IN6_SIN6_LEN - memcpy(&result_.su.in6.sin6_addr, *ap, sizeof(result_.su.in6.sin6_addr)); - break; - } + memcpy(&result_.su.in6.sin6_addr, ap, sizeof(result_.su.in6.sin6_addr)); break; default: assert(0);