From patchwork Tue Aug 3 21:29:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1513101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=P22lMPRj; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GfSlf5m3Cz9sRR for ; Wed, 4 Aug 2021 07:33:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EDC7396DC11 for ; Tue, 3 Aug 2021 21:33:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EDC7396DC11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628026380; bh=ARxWvGSbzcY+vHvbh4nFY8RNmOP51dURe+/yDmcvzmw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=P22lMPRjvZqiwWSRf61MZvrWpfBAgLc3K5OGPZArgSKk0bNQFZ7u0TTol+BEDW3bn TDnUCPm1JwHoiubza8nZJBO3dXVROC5qchLB1UFkXaJgwh2LO3N/ZOS05tkvcoqN/i za/wvL1Yt+AJbfgWYa81ggKVa4tQL/49nXv6m3qA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from antelope.elm.relay.mailchannels.net (antelope.elm.relay.mailchannels.net [23.83.212.4]) by sourceware.org (Postfix) with ESMTPS id 3856E3851C17 for ; Tue, 3 Aug 2021 21:29:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3856E3851C17 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 09C017E2CF0 for ; Tue, 3 Aug 2021 21:29:39 +0000 (UTC) Received: from pdx1-sub0-mail-a4.g.dreamhost.com (100-105-161-178.trex-nlb.outbound.svc.cluster.local [100.105.161.178]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A353E7E2A75 for ; Tue, 3 Aug 2021 21:29:38 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a4.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.105.161.178 (trex/6.3.3); Tue, 03 Aug 2021 21:29:38 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Cooing-Thread: 3b06033e6c215e37_1628026178889_4131000370 X-MC-Loop-Signature: 1628026178889:3391034243 X-MC-Ingress-Time: 1628026178889 Received: from pdx1-sub0-mail-a4.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a4.g.dreamhost.com (Postfix) with ESMTP id 6B58F8AAAA for ; Tue, 3 Aug 2021 14:29:38 -0700 (PDT) Received: from rhbox.redhat.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a4.g.dreamhost.com (Postfix) with ESMTPSA id 3FCB88AAA8 for ; Tue, 3 Aug 2021 14:29:36 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a4 To: libc-alpha@sourceware.org Subject: [PATCH 4/5] gaih_inet: Consolidate got_port code Date: Wed, 4 Aug 2021 02:59:18 +0530 Message-Id: <20210803212919.3059194-5-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803212919.3059194-1-siddhesh@sourceware.org> References: <20210803212919.3059194-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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;