From: Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org>
To: libc-alpha@sourceware.org
Subject: [PATCH 4/5] gaih_inet: Consolidate got_port code
Date: Wed, 4 Aug 2021 02:59:18 +0530 [thread overview]
Message-ID: <20210803212919.3059194-5-siddhesh@sourceware.org> (raw)
In-Reply-To: <20210803212919.3059194-1-siddhesh@sourceware.org>
Refactor the code to remove the unnecessary got_port goto across
conditional branches.
---
sysdeps/posix/getaddrinfo.c | 105 +++++++++++++++++-------------------
1 file changed, 48 insertions(+), 57 deletions(-)
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index fd05d53c1a..220cd41cde 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -359,65 +359,12 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
}
- int port = 0;
- if (service != NULL)
- {
- if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
- return -EAI_SERVICE;
-
- if (service->num < 0)
- {
- if (tp->name[0])
- {
- st = (struct gaih_servtuple *)
- alloca_account (sizeof (struct gaih_servtuple), alloca_used);
-
- int rc = gaih_inet_serv (service->name, tp, req, st, tmpbuf);
- if (__glibc_unlikely (rc != 0))
- return rc;
- }
- else
- {
- struct gaih_servtuple **pst = &st;
- for (tp++; tp->name[0]; tp++)
- {
- struct gaih_servtuple *newp;
-
- if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
- continue;
+ if (service != NULL && (tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
+ return -EAI_SERVICE;
- if (req->ai_socktype != 0
- && req->ai_socktype != tp->socktype)
- continue;
- if (req->ai_protocol != 0
- && !(tp->protoflag & GAI_PROTO_PROTOANY)
- && req->ai_protocol != tp->protocol)
- continue;
-
- newp = (struct gaih_servtuple *)
- alloca_account (sizeof (struct gaih_servtuple),
- alloca_used);
-
- if (gaih_inet_serv (service->name,
- tp, req, newp, tmpbuf) != 0)
- continue;
-
- *pst = newp;
- pst = &(newp->next);
- }
- if (st == (struct gaih_servtuple *) &nullserv)
- return -EAI_SERVICE;
- }
- }
- else
- {
- port = htons (service->num);
- goto got_port;
- }
- }
- else
+ if (service == NULL || service->num >= 0)
{
- got_port:
+ int port = service != NULL ? htons (service->num) : 0;
if (req->ai_socktype || req->ai_protocol)
{
@@ -450,6 +397,50 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
}
}
+ else
+ {
+ if (tp->name[0])
+ {
+ st = (struct gaih_servtuple *)
+ alloca_account (sizeof (struct gaih_servtuple), alloca_used);
+
+ int rc = gaih_inet_serv (service->name, tp, req, st, tmpbuf);
+ if (__glibc_unlikely (rc != 0))
+ return rc;
+ }
+ else
+ {
+ struct gaih_servtuple **pst = &st;
+ for (tp++; tp->name[0]; tp++)
+ {
+ struct gaih_servtuple *newp;
+
+ if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
+ continue;
+
+ if (req->ai_socktype != 0
+ && req->ai_socktype != tp->socktype)
+ continue;
+ if (req->ai_protocol != 0
+ && !(tp->protoflag & GAI_PROTO_PROTOANY)
+ && req->ai_protocol != tp->protocol)
+ continue;
+
+ newp = (struct gaih_servtuple *)
+ alloca_account (sizeof (struct gaih_servtuple),
+ alloca_used);
+
+ if (gaih_inet_serv (service->name,
+ tp, req, newp, tmpbuf) != 0)
+ continue;
+
+ *pst = newp;
+ pst = &(newp->next);
+ }
+ if (st == (struct gaih_servtuple *) &nullserv)
+ return -EAI_SERVICE;
+ }
+ }
bool malloc_name = false;
struct gaih_addrtuple *addrmem = NULL;
--
2.31.1
next prev parent reply other threads:[~2021-08-03 21:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-03 21:29 [PATCH 0/5] getaddrinfo spaghetti cleanups Siddhesh Poyarekar via Libc-alpha
2021-08-03 21:29 ` [PATCH 1/5] gaiconf_init: Refactor some bits for readability Siddhesh Poyarekar via Libc-alpha
2021-08-03 21:29 ` [PATCH 2/5] gai_init: Avoid jumping from if condition to its else counterpart Siddhesh Poyarekar via Libc-alpha
2021-08-03 21:29 ` [PATCH 3/5] getaddrinfo: Refactor code for readability Siddhesh Poyarekar via Libc-alpha
2021-08-03 21:29 ` Siddhesh Poyarekar via Libc-alpha [this message]
2021-08-03 21:29 ` [PATCH 5/5] gaih_inet: Make process_list label into a function Siddhesh Poyarekar via Libc-alpha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210803212919.3059194-5-siddhesh@sourceware.org \
--to=libc-alpha@sourceware.org \
--cc=siddhesh@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).