From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id 1B29B1F8C6 for ; Tue, 3 Aug 2021 21:33:06 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 524FF396DC1A for ; Tue, 3 Aug 2021 21:33:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 524FF396DC1A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628026385; 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=nWmz1GYOx4IJWMn3oJ4EKNXmAMaF2VvsT2qnCiey83+NlaFoAuxQrti10ji/Ji/ek wrAGHlTJEV/14OkYb4phtfwuoAO6AF1fyhetAqSuzLZssLauhAfEzV4/GpzhAGyEFH 02jA6l+ymXiqM6b3es+TI+FpFfqhqlWx2cbDv+7g= 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 Content-Transfer-Encoding: quoted-printable 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: , From: Siddhesh Poyarekar via Libc-alpha Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+e=80x24.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_serv= ice *service, } } =20 - int port =3D 0; - if (service !=3D NULL) - { - if ((tp->protoflag & GAI_PROTO_NOSERVICE) !=3D 0) - return -EAI_SERVICE; - - if (service->num < 0) - { - if (tp->name[0]) - { - st =3D (struct gaih_servtuple *) - alloca_account (sizeof (struct gaih_servtuple), alloca_used); - - int rc =3D gaih_inet_serv (service->name, tp, req, st, tmpbuf); - if (__glibc_unlikely (rc !=3D 0)) - return rc; - } - else - { - struct gaih_servtuple **pst =3D &st; - for (tp++; tp->name[0]; tp++) - { - struct gaih_servtuple *newp; - - if ((tp->protoflag & GAI_PROTO_NOSERVICE) !=3D 0) - continue; + if (service !=3D NULL && (tp->protoflag & GAI_PROTO_NOSERVICE) !=3D 0) + return -EAI_SERVICE; =20 - if (req->ai_socktype !=3D 0 - && req->ai_socktype !=3D tp->socktype) - continue; - if (req->ai_protocol !=3D 0 - && !(tp->protoflag & GAI_PROTO_PROTOANY) - && req->ai_protocol !=3D tp->protocol) - continue; - - newp =3D (struct gaih_servtuple *) - alloca_account (sizeof (struct gaih_servtuple), - alloca_used); - - if (gaih_inet_serv (service->name, - tp, req, newp, tmpbuf) !=3D 0) - continue; - - *pst =3D newp; - pst =3D &(newp->next); - } - if (st =3D=3D (struct gaih_servtuple *) &nullserv) - return -EAI_SERVICE; - } - } - else - { - port =3D htons (service->num); - goto got_port; - } - } - else + if (service =3D=3D NULL || service->num >=3D 0) { - got_port: + int port =3D service !=3D NULL ? htons (service->num) : 0; =20 if (req->ai_socktype || req->ai_protocol) { @@ -450,6 +397,50 @@ gaih_inet (const char *name, const struct gaih_servi= ce *service, } } } + else + { + if (tp->name[0]) + { + st =3D (struct gaih_servtuple *) + alloca_account (sizeof (struct gaih_servtuple), alloca_used); + + int rc =3D gaih_inet_serv (service->name, tp, req, st, tmpbuf); + if (__glibc_unlikely (rc !=3D 0)) + return rc; + } + else + { + struct gaih_servtuple **pst =3D &st; + for (tp++; tp->name[0]; tp++) + { + struct gaih_servtuple *newp; + + if ((tp->protoflag & GAI_PROTO_NOSERVICE) !=3D 0) + continue; + + if (req->ai_socktype !=3D 0 + && req->ai_socktype !=3D tp->socktype) + continue; + if (req->ai_protocol !=3D 0 + && !(tp->protoflag & GAI_PROTO_PROTOANY) + && req->ai_protocol !=3D tp->protocol) + continue; + + newp =3D (struct gaih_servtuple *) + alloca_account (sizeof (struct gaih_servtuple), + alloca_used); + + if (gaih_inet_serv (service->name, + tp, req, newp, tmpbuf) !=3D 0) + continue; + + *pst =3D newp; + pst =3D &(newp->next); + } + if (st =3D=3D (struct gaih_servtuple *) &nullserv) + return -EAI_SERVICE; + } + } =20 bool malloc_name =3D false; struct gaih_addrtuple *addrmem =3D NULL; --=20 2.31.1