* [PATCH] Deduplicate resolv/nss_dns/dns-host.c
@ 2014-02-13 12:38 Ondřej Bílka
2014-02-14 17:25 ` Mike Frysinger
0 siblings, 1 reply; 6+ messages in thread
From: Ondřej Bílka @ 2014-02-13 12:38 UTC (permalink / raw)
To: libc-alpha
Hi, when reviewing Andreas patch I noticed duplicated code. One way to
improve that is jump to exit logic. A second possibility would be put
gaih_getanswer into a else block. What do you prefer?
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Remove
duplicate code.
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 541c25a..4bf331e 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -342,16 +342,14 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
else
__set_errno (olderr);
- if (host_buffer.buf != orig_host_buffer)
- free (host_buffer.buf);
-
- return status;
+ goto free_and_return;
}
status = gaih_getanswer(host_buffer.buf, n, (const querybuf *) ans2p,
resplen2, name, pat, buffer, buflen,
errnop, herrnop, ttlp);
+ free_and_return:
if (host_buffer.buf != orig_host_buffer)
free (host_buffer.buf);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Deduplicate resolv/nss_dns/dns-host.c
2014-02-13 12:38 [PATCH] Deduplicate resolv/nss_dns/dns-host.c Ondřej Bílka
@ 2014-02-14 17:25 ` Mike Frysinger
2014-02-15 11:39 ` [PATCH v1.1] " Ondřej Bílka
0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2014-02-14 17:25 UTC (permalink / raw)
To: libc-alpha; +Cc: Ondřej Bílka
[-- Attachment #1: Type: text/plain, Size: 407 bytes --]
On Thursday, February 13, 2014 13:38:12 Ondřej Bílka wrote:
> Hi, when reviewing Andreas patch I noticed duplicated code. One way to
> improve that is jump to exit logic. A second possibility would be put
> gaih_getanswer into a else block. What do you prefer?
i don't mind either, but i think generally the preference is to avoid goto
when easily possible. so in this case, use the else.
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1.1] Deduplicate resolv/nss_dns/dns-host.c
2014-02-14 17:25 ` Mike Frysinger
@ 2014-02-15 11:39 ` Ondřej Bílka
2014-02-16 1:30 ` Mike Frysinger
2014-07-04 0:41 ` Allan McRae
0 siblings, 2 replies; 6+ messages in thread
From: Ondřej Bílka @ 2014-02-15 11:39 UTC (permalink / raw)
To: Mike Frysinger; +Cc: libc-alpha
On Fri, Feb 14, 2014 at 12:25:51PM -0500, Mike Frysinger wrote:
> On Thursday, February 13, 2014 13:38:12 OndÅej BÃlka wrote:
> > Hi, when reviewing Andreas patch I noticed duplicated code. One way to
> > improve that is jump to exit logic. A second possibility would be put
> > gaih_getanswer into a else block. What do you prefer?
>
> i don't mind either, but i think generally the preference is to avoid goto
> when easily possible. so in this case, use the else.
> -mike
OK, patch for this is following. It should cover one extra possibility when
__libc_res_nsearch fails and allocates separate buffer.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Remove
duplicate code
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 365de70..47f998c 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -315,7 +315,13 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
int n = __libc_res_nsearch (&_res, name, C_IN, T_UNSPEC,
host_buffer.buf->buf, anslen, &host_buffer.ptr,
&ans2p, &nans2p, &resplen2);
- if (n < 0)
+ if (n >= 0)
+ {
+ status = gaih_getanswer (host_buffer.buf, n, (const querybuf *) ans2p,
+ resplen2, name, pat, buffer, buflen,
+ errnop, herrnop, ttlp);
+ }
+ else
{
switch (errno)
{
@@ -342,17 +348,8 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
*errnop = EAGAIN;
else
__set_errno (olderr);
-
- if (host_buffer.buf != orig_host_buffer)
- free (host_buffer.buf);
-
- return status;
}
- status = gaih_getanswer(host_buffer.buf, n, (const querybuf *) ans2p,
- resplen2, name, pat, buffer, buflen,
- errnop, herrnop, ttlp);
-
/* Check whether ans2p was separately allocated. */
if (host_buffer.buf != orig_host_buffer)
anslen = MAXPACKET;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1.1] Deduplicate resolv/nss_dns/dns-host.c
2014-02-15 11:39 ` [PATCH v1.1] " Ondřej Bílka
@ 2014-02-16 1:30 ` Mike Frysinger
2014-07-04 0:41 ` Allan McRae
1 sibling, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2014-02-16 1:30 UTC (permalink / raw)
To: Ondřej Bílka; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 731 bytes --]
On Saturday, February 15, 2014 12:39:19 Ondřej Bílka wrote:
> On Fri, Feb 14, 2014 at 12:25:51PM -0500, Mike Frysinger wrote:
> > On Thursday, February 13, 2014 13:38:12 Ondřej Bílka wrote:
> > > Hi, when reviewing Andreas patch I noticed duplicated code. One way to
> > > improve that is jump to exit logic. A second possibility would be put
> > >
> > > gaih_getanswer into a else block. What do you prefer?
> >
> > i don't mind either, but i think generally the preference is to avoid goto
> > when easily possible. so in this case, use the else.
> > -mike
>
> OK, patch for this is following. It should cover one extra possibility when
> __libc_res_nsearch fails and allocates separate buffer.
OK
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1.1] Deduplicate resolv/nss_dns/dns-host.c
2014-02-15 11:39 ` [PATCH v1.1] " Ondřej Bílka
2014-02-16 1:30 ` Mike Frysinger
@ 2014-07-04 0:41 ` Allan McRae
2014-08-02 13:16 ` Mike Frysinger
1 sibling, 1 reply; 6+ messages in thread
From: Allan McRae @ 2014-07-04 0:41 UTC (permalink / raw)
To: Ondřej Bílka, Mike Frysinger; +Cc: libc-alpha
On 15/02/14 21:39, OndÅej BÃlka wrote:
> On Fri, Feb 14, 2014 at 12:25:51PM -0500, Mike Frysinger wrote:
>> On Thursday, February 13, 2014 13:38:12 OndÅej BÃlka wrote:
>>> Hi, when reviewing Andreas patch I noticed duplicated code. One way to
>>> improve that is jump to exit logic. A second possibility would be put
>>> gaih_getanswer into a else block. What do you prefer?
>>
>> i don't mind either, but i think generally the preference is to avoid goto
>> when easily possible. so in this case, use the else.
>> -mike
>
> OK, patch for this is following. It should cover one extra possibility when
> __libc_res_nsearch fails and allocates separate buffer.
>
> * resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Remove
> duplicate code
>
OndÅej: This was committed without a ChangeLog entry. Can you insert
one in the appropriate place.
Thanks,
Allan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1.1] Deduplicate resolv/nss_dns/dns-host.c
2014-07-04 0:41 ` Allan McRae
@ 2014-08-02 13:16 ` Mike Frysinger
0 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2014-08-02 13:16 UTC (permalink / raw)
To: Ondřej Bílka; +Cc: Allan McRae, libc-alpha
[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]
On Fri 04 Jul 2014 10:41:25 Allan McRae wrote:
> On 15/02/14 21:39, Ondřej Bílka wrote:
> > On Fri, Feb 14, 2014 at 12:25:51PM -0500, Mike Frysinger wrote:
> >> On Thursday, February 13, 2014 13:38:12 Ondřej Bílka wrote:
> >>> Hi, when reviewing Andreas patch I noticed duplicated code. One way to
> >>> improve that is jump to exit logic. A second possibility would be put
> >>>
> >>> gaih_getanswer into a else block. What do you prefer?
> >>
> >> i don't mind either, but i think generally the preference is to avoid
> >> goto
> >> when easily possible. so in this case, use the else.
> >> -mike
> >
> > OK, patch for this is following. It should cover one extra possibility
> > when
> > __libc_res_nsearch fails and allocates separate buffer.
> >
> > * resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Remove
> > duplicate code
>
> Ondřej: This was committed without a ChangeLog entry. Can you insert
> one in the appropriate place.
looks like Allan did this for you ~3 weeks later. i wonder why he had to.
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-08-02 13:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-13 12:38 [PATCH] Deduplicate resolv/nss_dns/dns-host.c Ondřej Bílka
2014-02-14 17:25 ` Mike Frysinger
2014-02-15 11:39 ` [PATCH v1.1] " Ondřej Bílka
2014-02-16 1:30 ` Mike Frysinger
2014-07-04 0:41 ` Allan McRae
2014-08-02 13:16 ` Mike Frysinger
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).