svn commit: r289925 - head/lib/libc/gen

Garrett Cooper ngie at FreeBSD.org
Sun Oct 25 07:42:58 UTC 2015


Author: ngie
Date: Sun Oct 25 07:42:56 2015
New Revision: 289925
URL: https://svnweb.freebsd.org/changeset/base/289925

Log:
  Fix compiling with gcc [4.2.1] after r287797 when MK_HESOID == no and
  MK_NIS == no by converting `i` back to an int, and instead cast the loop
  comparison to `int`
  
  The loop comparison is iterating the len(ns_dtab)-1, because
  the last element is the sentinel tuple { NULL, NULL, NULL, }, so when
  both HESOID and NIS are off, len(ns_dtab)-1 == 1 - 1 == 0, and the loop
  is skipped because the expression is tautologically false
  
  While here, convert `(sizeof(x) / sizeof(x[0]))` to `nitems(x)`
  
  Tested with: clang 3.7.0, gcc 4.2.1, and gcc 4.9.4 [*] with MK_NIS={no,yes}
               and by running bash -lc 'id -u && id -g && id'
  
  * gcc 4.9.4 needs another patch in order for the compile to succeed
    with -Werror with lib/libc/gen/getgrent.c
  
  Reported by: jhibbits

Modified:
  head/lib/libc/gen/getgrent.c
  head/lib/libc/gen/getpwent.c

Modified: head/lib/libc/gen/getgrent.c
==============================================================================
--- head/lib/libc/gen/getgrent.c	Sun Oct 25 07:26:12 2015	(r289924)
+++ head/lib/libc/gen/getgrent.c	Sun Oct 25 07:42:56 2015	(r289925)
@@ -1239,14 +1239,13 @@ compat_setgrent(void *retval, void *mdat
 	int		 rv, stayopen;
 
 #define set_setent(x, y) do {	 				\
-	unsigned int i;						\
-								\
-	for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++)	\
+	int i;							\
+	for (i = 0; i < (int)(nitems(x) - 1); i++)		\
 		x[i].mdata = (void *)y;				\
 } while (0)
 
 	rv = compat_getstate(&st);
-	if (rv != 0) 
+	if (rv != 0)
 		return (NS_UNAVAIL);
 	switch ((enum constants)mdata) {
 	case SETGRENT:
@@ -1309,9 +1308,8 @@ compat_group(void *retval, void *mdata, 
 	int			 rv, stayopen, *errnop;
 
 #define set_lookup_type(x, y) do { 				\
-	unsigned int i;						\
-								\
-	for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++)	\
+	int i;							\
+	for (i = 0; i < (int)(nitems(x) - 1); i++)		\
 		x[i].mdata = (void *)y;				\
 } while (0)
 

Modified: head/lib/libc/gen/getpwent.c
==============================================================================
--- head/lib/libc/gen/getpwent.c	Sun Oct 25 07:26:12 2015	(r289924)
+++ head/lib/libc/gen/getpwent.c	Sun Oct 25 07:42:56 2015	(r289925)
@@ -1607,10 +1607,9 @@ compat_redispatch(struct compat_state *s
 		{ NULL, NULL, NULL }
 	};
 	void		*discard;
-	int		 rv, e;
-	unsigned int	 i;
+	int		 e, i, rv;
 
-	for (i = 0; i < sizeof(dtab)/sizeof(dtab[0]) - 1; i++)
+	for (i = 0; i < (int)(nitems(dtab) - 1); i++)
 		dtab[i].mdata = (void *)lookup_how;
 more:
 	pwd_init(pwd);
@@ -1703,9 +1702,8 @@ compat_setpwent(void *retval, void *mdat
 	int			 rv, stayopen;
 
 #define set_setent(x, y) do {	 				\
-	unsigned int i;						\
-								\
-	for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++)	\
+	int i;							\
+	for (i = 0; i < (int)(nitems(x) - 1); i++)		\
 		x[i].mdata = (void *)y;				\
 } while (0)
 


More information about the svn-src-head mailing list