8597553
commit bee05c9d58a34ec5886faf3b56ecaa56355d94bf
8597553
Author: Florian Weimer <fweimer@redhat.com>
8597553
Date:   Wed Apr 19 14:29:11 2017 +0200
8597553
8597553
    resolv: Replace __builtin_expect with __glibc_unlikely/__glibc_likely
8597553
8597553
diff --git a/resolv/gai_suspend.c b/resolv/gai_suspend.c
8597553
index 3ee6a08b4fd9f2fb..a86bd4360d6b03e8 100644
8597553
--- a/resolv/gai_suspend.c
8597553
+++ b/resolv/gai_suspend.c
8597553
@@ -141,7 +141,7 @@ gai_suspend (const struct gaicb *const list[], int ent,
8597553
 	  /* An error occurred.  Possibly it's EINTR.  We have to translate
8597553
 	     the timeout error report of `pthread_cond_timedwait' to the
8597553
 	     form expected from `gai_suspend'.  */
8597553
-	  if (__builtin_expect (result, ETIMEDOUT) == ETIMEDOUT)
8597553
+	  if (__glibc_likely (result == ETIMEDOUT))
8597553
 	    result = EAI_AGAIN;
8597553
 	  else if (result == EINTR)
8597553
 	    result = EAI_INTR;
8597553
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
8597553
index 705b3c9c078c41bf..7099d093f357e16c 100644
8597553
--- a/resolv/nss_dns/dns-host.c
8597553
+++ b/resolv/nss_dns/dns-host.c
8597553
@@ -619,7 +619,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
   ancount = ntohs (hp->ancount);
8597553
   qdcount = ntohs (hp->qdcount);
8597553
   cp = answer->buf + HFIXEDSZ;
8597553
-  if (__builtin_expect (qdcount, 1) != 1)
8597553
+  if (__glibc_unlikely (qdcount != 1))
8597553
     {
8597553
       *h_errnop = NO_RECOVERY;
8597553
       return NSS_STATUS_UNAVAIL;
8597553
@@ -633,7 +633,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
 			packtmp, sizeof packtmp);
8597553
   if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
8597553
     {
8597553
-      if (__builtin_expect (errno, 0) == EMSGSIZE)
8597553
+      if (__glibc_unlikely (errno) == EMSGSIZE)
8597553
 	goto too_small;
8597553
 
8597553
       n = -1;
8597553
@@ -642,13 +642,19 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
   if (n > 0 && bp[0] == '.')
8597553
     bp[0] = '\0';
8597553
 
8597553
-  if (__builtin_expect (n < 0 || ((*name_ok) (bp) == 0 && (errno = EBADMSG)),
8597553
-			0))
8597553
+  if (__glibc_unlikely (n < 0))
8597553
     {
8597553
       *errnop = errno;
8597553
       *h_errnop = NO_RECOVERY;
8597553
       return NSS_STATUS_UNAVAIL;
8597553
     }
8597553
+  if (__glibc_unlikely (name_ok (bp) == 0))
8597553
+    {
8597553
+      errno = EBADMSG;
8597553
+      *errnop = EBADMSG;
8597553
+      *h_errnop = NO_RECOVERY;
8597553
+      return NSS_STATUS_UNAVAIL;
8597553
+    }
8597553
   cp += n + QFIXEDSZ;
8597553
 
8597553
   if (qtype == T_A || qtype == T_AAAA)
8597553
@@ -690,7 +696,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
 			    packtmp, sizeof packtmp);
8597553
       if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
8597553
 	{
8597553
-	  if (__builtin_expect (errno, 0) == EMSGSIZE)
8597553
+	  if (__glibc_unlikely (errno == EMSGSIZE))
8597553
 	    goto too_small;
8597553
 
8597553
 	  n = -1;
8597553
@@ -750,7 +756,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
 	  /* Store alias.  */
8597553
 	  *ap++ = bp;
8597553
 	  n = strlen (bp) + 1;		/* For the \0.  */
8597553
-	  if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
8597553
+	  if (__glibc_unlikely (n >= MAXHOSTNAMELEN))
8597553
 	    {
8597553
 	      ++had_error;
8597553
 	      continue;
8597553
@@ -761,7 +767,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
 	  n = strlen (tbuf) + 1;	/* For the \0.  */
8597553
 	  if (__glibc_unlikely (n > linebuflen))
8597553
 	    goto too_small;
8597553
-	  if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
8597553
+	  if (__glibc_unlikely (n >= MAXHOSTNAMELEN))
8597553
 	    {
8597553
 	      ++had_error;
8597553
 	      continue;
8597553
@@ -789,7 +795,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
 	  n = strlen (tbuf) + 1;   /* For the \0.  */
8597553
 	  if (__glibc_unlikely (n > linebuflen))
8597553
 	    goto too_small;
8597553
-	  if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
8597553
+	  if (__glibc_unlikely (n >= MAXHOSTNAMELEN))
8597553
 	    {
8597553
 	      ++had_error;
8597553
 	      continue;
8597553
@@ -821,7 +827,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
 				packtmp, sizeof packtmp);
8597553
 	  if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
8597553
 	    {
8597553
-	      if (__builtin_expect (errno, 0) == EMSGSIZE)
8597553
+	      if (__glibc_unlikely (errno == EMSGSIZE))
8597553
 		goto too_small;
8597553
 
8597553
 	      n = -1;
8597553
@@ -854,7 +860,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
8597553
 	  return NSS_STATUS_SUCCESS;
8597553
 	case T_A:
8597553
 	case T_AAAA:
8597553
-	  if (__builtin_expect (strcasecmp (result->h_name, bp), 0) != 0)
8597553
+	  if (__glibc_unlikely (strcasecmp (result->h_name, bp) != 0))
8597553
 	    {
8597553
 	      cp += n;
8597553
 	      continue;			/* XXX - had_error++ ? */
8597553
@@ -975,7 +981,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
8597553
      it later.  */
8597553
   if (n != -1 && __ns_name_ntop (packtmp, buffer, buflen) == -1)
8597553
     {
8597553
-      if (__builtin_expect (errno, 0) == EMSGSIZE)
8597553
+      if (__glibc_unlikely (errno == EMSGSIZE))
8597553
 	{
8597553
 	too_small:
8597553
 	  *errnop = ERANGE;
8597553
@@ -986,13 +992,19 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
8597553
       n = -1;
8597553
     }
8597553
 
8597553
-  if (__builtin_expect (n < 0 || (res_hnok (buffer) == 0
8597553
-				  && (errno = EBADMSG)), 0))
8597553
+  if (__glibc_unlikely (n < 0))
8597553
     {
8597553
       *errnop = errno;
8597553
       *h_errnop = NO_RECOVERY;
8597553
       return NSS_STATUS_UNAVAIL;
8597553
     }
8597553
+  if (__glibc_unlikely (res_hnok (buffer) == 0))
8597553
+    {
8597553
+      errno = EBADMSG;
8597553
+      *errnop = EBADMSG;
8597553
+      *h_errnop = NO_RECOVERY;
8597553
+      return NSS_STATUS_UNAVAIL;
8597553
+    }
8597553
   cp += n + QFIXEDSZ;
8597553
 
8597553
   int haveanswer = 0;
8597553
@@ -1014,7 +1026,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
8597553
       if (n != -1 &&
8597553
 	  (h_namelen = __ns_name_ntop (packtmp, buffer, buflen)) == -1)
8597553
 	{
8597553
-	  if (__builtin_expect (errno, 0) == EMSGSIZE)
8597553
+	  if (__glibc_unlikely (errno == EMSGSIZE))
8597553
 	    goto too_small;
8597553
 
8597553
 	  n = -1;
8597553
@@ -1128,8 +1140,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
8597553
 	  buffer += pad;
8597553
 	  buflen = buflen > pad ? buflen - pad : 0;
8597553
 
8597553
-	  if (__builtin_expect (buflen < sizeof (struct gaih_addrtuple),
8597553
-				0))
8597553
+	  if (__glibc_unlikely (buflen < sizeof (struct gaih_addrtuple)))
8597553
 	    goto too_small;
8597553
 
8597553
 	  *pat = (struct gaih_addrtuple *) buffer;
8597553
diff --git a/resolv/res_init.c b/resolv/res_init.c
8597553
index 923724f86d6a0edc..23676e994dd58be7 100644
8597553
--- a/resolv/res_init.c
8597553
+++ b/resolv/res_init.c
8597553
@@ -356,7 +356,7 @@ __res_vinit(res_state statp, int preinit) {
8597553
 	    statp->nsort = nsort;
8597553
 	    (void) fclose(fp);
8597553
 	}
8597553
-	if (__builtin_expect(statp->nscount == 0, 0)) {
8597553
+	if (__glibc_unlikely (statp->nscount == 0)) {
8597553
 	    statp->nsaddr.sin_addr = __inet_makeaddr(IN_LOOPBACKNET, 1);
8597553
 	    statp->nsaddr.sin_family = AF_INET;
8597553
 	    statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
8597553
diff --git a/resolv/res_query.c b/resolv/res_query.c
8597553
index ec65bab04153c2ff..0ca3a650282ec7f0 100644
8597553
--- a/resolv/res_query.c
8597553
+++ b/resolv/res_query.c
8597553
@@ -199,7 +199,7 @@ __libc_res_nquery(res_state statp,
8597553
 	    nquery1 = n;
8597553
 	  }
8597553
 
8597553
-	if (__builtin_expect (n <= 0, 0) && !use_malloc) {
8597553
+	if (__glibc_unlikely (n <= 0) && !use_malloc) {
8597553
 		/* Retry just in case res_nmkquery failed because of too
8597553
 		   short buffer.  Shouldn't happen.  */
8597553
 		bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * MAXPACKET;
8597553
diff --git a/resolv/res_send.c b/resolv/res_send.c
8597553
index 440da90a0b381b84..1835ec7ee507d215 100644
8597553
--- a/resolv/res_send.c
8597553
+++ b/resolv/res_send.c
8597553
@@ -424,7 +424,7 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
8597553
 	 * Some resolvers want to even out the load on their nameservers.
8597553
 	 * Note that RES_BLAST overrides RES_ROTATE.
8597553
 	 */
8597553
-	if (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0)) {
8597553
+	if (__glibc_unlikely ((statp->options & RES_ROTATE) != 0)) {
8597553
 		struct sockaddr_in ina;
8597553
 		struct sockaddr_in6 *inp;
8597553
 		int lastns = statp->nscount - 1;