about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-04-21 16:15:11 +0000
committerUlrich Drepper <drepper@redhat.com>2000-04-21 16:15:11 +0000
commita711dd4ba8f2c71a260a3f7539c0e86175f97a21 (patch)
tree1bf9e3eb9a49f3b9cdcd0dee9515339486170f74
parent761df3a7aa6eb65aa66c78e6c1da627e453de458 (diff)
downloadglibc-a711dd4ba8f2c71a260a3f7539c0e86175f97a21.tar.gz
glibc-a711dd4ba8f2c71a260a3f7539c0e86175f97a21.tar.xz
glibc-a711dd4ba8f2c71a260a3f7539c0e86175f97a21.zip
Update.
2000-04-21  Ulrich Drepper  <drepper@redhat.com>

	* iconv/iconv.c (iconv): Add __builtin_expect where useful.
	* iconv/iconv_close.c (iconv_close): Likewise.
	* iconv/iconv_open.c (iconv_open): Likewise.

	* grp/putgrent.c (putgrent): Unlock steam if fprintf failed.  Add
	__builtin_expect where useful.

	* grp/initgroups.c (initgroups): Test for result of memory
	allocation and punt if it fails.

	* dirent/scandir.c (scandir): Add __builtin_expect where useful.
	* grp/fgetgrent.c (fgetfrent): Likewise.
	* grp/fgetgrent_r.c (__fgetgrent_r): Likewise.
-rw-r--r--ChangeLog16
-rw-r--r--dirent/scandir.c10
-rw-r--r--grp/fgetgrent.c6
-rw-r--r--grp/fgetgrent_r.c8
-rw-r--r--grp/initgroups.c7
-rw-r--r--grp/putgrent.c11
-rw-r--r--iconv/iconv.c6
-rw-r--r--iconv/iconv_close.c4
-rw-r--r--iconv/iconv_open.c4
9 files changed, 47 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 32346c52d8..ece1f65a5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2000-04-21  Ulrich Drepper  <drepper@redhat.com>
+
+	* iconv/iconv.c (iconv): Add __builtin_expect where useful.
+	* iconv/iconv_close.c (iconv_close): Likewise.
+	* iconv/iconv_open.c (iconv_open): Likewise.
+
+	* grp/putgrent.c (putgrent): Unlock steam if fprintf failed.  Add
+	__builtin_expect where useful.
+
+	* grp/initgroups.c (initgroups): Test for result of memory
+	allocation and punt if it fails.
+
+	* dirent/scandir.c (scandir): Add __builtin_expect where useful.
+	* grp/fgetgrent.c (fgetfrent): Likewise.
+	* grp/fgetgrent_r.c (__fgetgrent_r): Likewise.
+
 2000-04-21  Jakub Jelinek  <jakub@redhat.com>
 
 	* libio/vasprintf.c: Include string.h to get memcpy prototype.
diff --git a/dirent/scandir.c b/dirent/scandir.c
index ed9071df6e..9b4548cd16 100644
--- a/dirent/scandir.c
+++ b/dirent/scandir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+/* Copyright (C) 1992-1998, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -25,8 +25,8 @@ int
 scandir (dir, namelist, select, cmp)
      const char *dir;
      struct dirent ***namelist;
-     int (*select) __P ((const struct dirent *));
-     int (*cmp) __P ((const void *, const void *));
+     int (*select) (const struct dirent *);
+     int (*cmp) (const void *, const void *);
 {
   DIR *dp = __opendir (dir);
   struct dirent **v = NULL;
@@ -50,7 +50,7 @@ scandir (dir, namelist, select, cmp)
 	/* Ignore errors from select or readdir */
 	__set_errno (0);
 
-	if (i == vsize)
+	if (__builtin_expect (i == vsize, 0))
 	  {
 	    struct dirent **new;
 	    if (vsize == 0)
@@ -71,7 +71,7 @@ scandir (dir, namelist, select, cmp)
 	v[i++] = (struct dirent *) memcpy (vnew, d, dsize);
       }
 
-  if (errno != 0)
+  if (__builtin_expect (errno, 0) != 0)
     {
       save = errno;
       (void) __closedir (dp);
diff --git a/grp/fgetgrent.c b/grp/fgetgrent.c
index 245524f178..69507d97e7 100644
--- a/grp/fgetgrent.c
+++ b/grp/fgetgrent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1996, 1997, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -38,7 +38,7 @@ fgetgrent (FILE *stream)
   struct group *result;
   int save;
 
-  if (fgetpos (stream, &pos) != 0)
+  if (__builtin_expect (fgetpos (stream, &pos), 0) != 0)
     return NULL;
 
   /* Get lock.  */
@@ -58,7 +58,7 @@ fgetgrent (FILE *stream)
       char *new_buf;
       buffer_size += NSS_BUFLEN_GROUP;
       new_buf = realloc (buffer, buffer_size);
-      if (new_buf == NULL)
+      if (__builtin_expect (new_buf == NULL, 0))
 	{
 	  /* We are out of memory.  Free the current buffer so that the
 	     process gets a chance for a normal termination.  */
diff --git a/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
index 0b1d782586..058b0b3e74 100644
--- a/grp/fgetgrent_r.c
+++ b/grp/fgetgrent_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996-1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -70,14 +70,14 @@ __fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
     {
       buffer[buflen - 1] = '\xff';
       p = fgets_unlocked (buffer, buflen, stream);
-      if (p == NULL && feof_unlocked (stream))
+      if (__builtin_expect (p == NULL, 0) && feof_unlocked (stream))
 	{
 	  funlockfile (stream);
 	  *result = NULL;
 	  __set_errno (ENOENT);
 	  return errno;
 	}
-      if (p == NULL || buffer[buflen - 1] != '\xff')
+      if (__builtin_expect (p == NULL, 0) || buffer[buflen - 1] != '\xff')
 	{
 	  funlockfile (stream);
 	  *result = NULL;
@@ -97,7 +97,7 @@ __fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
 
   funlockfile (stream);
 
-  if (parse_result == -1)
+  if (__builtin_expect (parse_result, 0) == -1)
     {
       /* The parser ran out of space.  */
       *result = NULL;
diff --git a/grp/initgroups.c b/grp/initgroups.c
index fd30ebf7e0..06c48bb040 100644
--- a/grp/initgroups.c
+++ b/grp/initgroups.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989, 91, 93, 96, 97, 98, 99 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 91, 93, 1996-1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -163,7 +163,10 @@ initgroups (user, group)
     size = 16;
 #endif
 
-  groups = malloc (size * sizeof (gid_t *));
+  groups = (gid_t *) malloc (size * sizeof (gid_t));
+  if (__builtin_expect (groups == NULL, 0))
+    /* No more memory.  */
+    return -1;
 
   groups[0] = group;
 
diff --git a/grp/putgrent.c b/grp/putgrent.c
index a119ebed17..11b64eca63 100644
--- a/grp/putgrent.c
+++ b/grp/putgrent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1996, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 96, 98, 99, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -36,7 +36,7 @@ putgrent (gr, stream)
 {
   int retval;
 
-  if (gr == NULL || stream == NULL)
+  if (__builtin_expect (gr == NULL, 0) || __builtin_expect (stream == NULL, 0))
     {
       __set_errno (EINVAL);
       return -1;
@@ -46,8 +46,11 @@ putgrent (gr, stream)
 
   retval = fprintf (stream, "%s:%s:%u:",
 		    gr->gr_name, _S (gr->gr_passwd), gr->gr_gid);
-  if (retval < 0)
-    return -1;
+  if (__builtin_expect (retval, 0) < 0)
+    {
+      funlockfile (stream);
+      return -1;
+    }
 
   if (gr->gr_mem != NULL)
     {
diff --git a/iconv/iconv.c b/iconv/iconv.c
index c1b96164e5..c7ff73c428 100644
--- a/iconv/iconv.c
+++ b/iconv/iconv.c
@@ -1,6 +1,6 @@
 /* Convert characters in input buffer using conversion descriptor to
    output buffer.
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -37,7 +37,7 @@ iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf,
   size_t converted;
   int result;
 
-  if (inbuf == NULL || *inbuf == NULL)
+  if (__gconv_builtin (inbuf == NULL || *inbuf == NULL), 0)
     {
       if (outbuf == NULL || *outbuf == NULL)
 	result = __gconv (gcd, NULL, NULL, NULL, NULL, &converted);
@@ -61,7 +61,7 @@ iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf,
   if (outstart != NULL)
     *outbytesleft -= *outbuf - outstart;
 
-  switch (result)
+  switch (__builtin_expect (result, __GCONV_OK))
     {
     case __GCONV_ILLEGAL_DESCRIPTOR:
       __set_errno (EBADF);
diff --git a/iconv/iconv_close.c b/iconv/iconv_close.c
index 6f81aa2595..c999e44dac 100644
--- a/iconv/iconv_close.c
+++ b/iconv/iconv_close.c
@@ -1,5 +1,5 @@
 /* Release any resource associated with given conversion descriptor.
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -27,7 +27,7 @@
 int
 iconv_close (iconv_t cd)
 {
-  if (cd == (iconv_t *) -1L)
+  if (__builtin_expect (cd == (iconv_t *) -1L, 0))
     {
       __set_errno (EBADF);
       return -1;
diff --git a/iconv/iconv_open.c b/iconv/iconv_open.c
index 96b910ea94..7f06947c9a 100644
--- a/iconv/iconv_open.c
+++ b/iconv/iconv_open.c
@@ -1,5 +1,5 @@
 /* Get descriptor for character set conversion.
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -87,7 +87,7 @@ iconv_open (const char *tocode, const char *fromcode)
 
   res = __gconv_open (tocode, fromcode, &cd, 0);
 
-  if (res != __GCONV_OK)
+  if (__builtin_expect (res, __GCONV_OK) != __GCONV_OK)
     {
       /* We must set the error number according to the specs.  */
       if (res == __GCONV_NOCONV || res == __GCONV_NODB)