From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2206) id 7D615385841D; Tue, 1 Mar 2022 02:41:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D615385841D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Siddhesh Poyarekar To: glibc-cvs@sourceware.org Subject: [glibc/siddhesh/gai-cleanup2] gaih_inet: Clean up some variables and branches X-Act-Checkin: glibc X-Git-Author: Siddhesh Poyarekar X-Git-Refname: refs/heads/siddhesh/gai-cleanup2 X-Git-Oldrev: fb77c48d079662d513597f6ec0960ee70c7f4664 X-Git-Newrev: 67d46da1a14827d8d89c7aba5c55401495c44fbc Message-Id: <20220301024122.7D615385841D@sourceware.org> Date: Tue, 1 Mar 2022 02:41:22 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2022 02:41:22 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=67d46da1a14827d8d89c7aba5c55401495c44fbc commit 67d46da1a14827d8d89c7aba5c55401495c44fbc Author: Siddhesh Poyarekar Date: Mon Feb 28 22:30:04 2022 +0530 gaih_inet: Clean up some variables and branches Consolidate some redundant assignments and make the result loop structure a bit simpler. Signed-off-by: Siddhesh Poyarekar Diff: --- sysdeps/posix/getaddrinfo.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 1d248c8835..3dd2f8cff7 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -1094,7 +1094,6 @@ gaih_inet (const char *name, const struct gaih_service *service, / sizeof (struct gaih_typeproto)] = {0}; struct gaih_addrtuple *at = NULL; - bool got_ipv6 = false; char *canon = NULL; const char *orig_name = name; @@ -1156,7 +1155,6 @@ gaih_inet (const char *name, const struct gaih_service *service, { at = res.at; canon = at->name; - got_ipv6 = res.got_ipv6; goto process_list; } #endif @@ -1167,10 +1165,8 @@ gaih_inet (const char *name, const struct gaih_service *service, { at = res.at; canon = at->name; - got_ipv6 = res.got_ipv6; } - process_list: if (at == NULL) { result = -EAI_NONAME; @@ -1205,19 +1201,18 @@ gaih_inet (const char *name, const struct gaih_service *service, } } +process_list: { /* Set up the canonical name if we need it. */ if ((result = process_canonname (req, orig_name, &canon)) != 0) goto free_and_return; - struct gaih_addrtuple *at2 = at; size_t socklen; sa_family_t family; - /* - buffer is the size of an unformatted IPv6 address in printable format. - */ - while (at2 != NULL) + /* Buffer is the size of an unformatted IPv6 address in printable + format. */ + for (struct gaih_addrtuple *at2 = at; at2 != NULL; at2 = at2->next) { family = at2->family; if (family == AF_INET6) @@ -1227,10 +1222,10 @@ gaih_inet (const char *name, const struct gaih_service *service, /* If we looked up IPv4 mapped address discard them here if the caller isn't interested in all address and we have found at least one IPv6 address. */ - if (got_ipv6 + if (res.got_ipv6 && (req->ai_flags & (AI_V4MAPPED|AI_ALL)) == AI_V4MAPPED && IN6_IS_ADDR_V4MAPPED (at2->addr)) - goto ignore; + continue; } else socklen = sizeof (struct sockaddr_in); @@ -1290,9 +1285,6 @@ gaih_inet (const char *name, const struct gaih_service *service, } ++*naddrs; - - ignore: - at2 = at2->next; } }