This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Minor nit in nis_leaf_of_r


Hi!

Recent change in nis_subr.c:
@@ -39,22 +39,13 @@ nis_leaf_of_r (const_nis_name name, char
   while (name[i] != '.' && name[i] != '\0')
     i++;

-  if (i > buflen - 1)
+  if (__builtin_expect (i > buflen - 1, 0))
     {
       __set_errno (ERANGE);
       return NULL;
     }

-  if (i > 0)
-    {
-      if ((size_t)i >= buflen)
-       {
-         __set_errno (ERANGE);
-         return NULL;
-       }
-
-      *((char *) __mempcpy (buffer, name, i)) = '\0';
-    }
+  *((char *) __mempcpy (buffer, name, i)) = '\0';

   return buffer;
 }
together with removing unnecessary code and no longer forgetting
to zero-terminate in i == 0 case also no longer handles
buflen == 0 gracefully.  i >= buflen test should behave the same
as the current i > buflen - 1, except for buflen == 0.

2005-08-15  Jakub Jelinek  <jakub@redhat.com>

	* nis/nis_subr.c (nis_leaf_of_r): Handle buflen == 0 correctly.

--- libc/nis/nis_subr.c.jj	2005-08-08 09:14:54.000000000 +0200
+++ libc/nis/nis_subr.c	2005-08-15 13:59:06.000000000 +0200
@@ -39,7 +39,7 @@ nis_leaf_of_r (const_nis_name name, char
   while (name[i] != '.' && name[i] != '\0')
     i++;
 
-  if (__builtin_expect (i > buflen - 1, 0))
+  if (__builtin_expect (i >= buflen, 0))
     {
       __set_errno (ERANGE);
       return NULL;


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]