[Pkg-shadow-commits] r2105 - in upstream/trunk: . src

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Tue Jun 10 19:29:55 UTC 2008


Author: nekral-guest
Date: 2008-06-10 19:29:54 +0000 (Tue, 10 Jun 2008)
New Revision: 2105

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/groups.c
Log:
	* src/groups.c: Use a bool when possible instead of int integers.
	* src/groups.c: Add brackets and parenthesis.
	* src/groups.c: Avoid implicit conversion of pointers / integers
	to booleans.
	* src/groups.c: Avoid assignments in comparisons.
	* src/groups.c: Ignore the return value of putchar(), printf()
	* src/groups.c: Ignore return value of setlocale(),
	bindtextdomain(), and textdomain().


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-06-10 19:18:44 UTC (rev 2104)
+++ upstream/trunk/ChangeLog	2008-06-10 19:29:54 UTC (rev 2105)
@@ -1,5 +1,16 @@
 2008-06-10  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/groups.c: Use a bool when possible instead of int integers.
+	* src/groups.c: Add brackets and parenthesis.
+	* src/groups.c: Avoid implicit conversion of pointers / integers
+	to booleans.
+	* src/groups.c: Avoid assignments in comparisons.
+	* src/groups.c: Ignore the return value of putchar(), printf()
+	* src/groups.c: Ignore return value of setlocale(),
+	bindtextdomain(), and textdomain().
+
+2008-06-10  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/grpconv.c: Use a bool when possible instead of int integers.
 	* src/grpconv.c: Add brackets and parenthesis.
 	* src/grpconv.c: Ignore return value of setlocale(),

Modified: upstream/trunk/src/groups.c
===================================================================
--- upstream/trunk/src/groups.c	2008-06-10 19:18:44 UTC (rev 2104)
+++ upstream/trunk/src/groups.c	2008-06-10 19:29:54 UTC (rev 2105)
@@ -58,34 +58,47 @@
 	int groups = 0;
 	struct group *grp;
 	struct passwd *pwd;
-	int flag = 0;
+	bool flag = false;
 
-	/* local, no need for xgetpwnam */
-	if ((pwd = getpwnam (member)) == 0) {
-		fprintf (stderr, _("%s: unknown user %s\n"), Prog, member);
+	pwd = getpwnam (member); /* local, no need for xgetpwnam */
+	if (NULL == pwd) {
+		(void) fprintf (stderr, _("%s: unknown user %s\n"),
+		                Prog, member);
 		exit (1);
 	}
+
 	setgrent ();
-	while ((grp = getgrent ())) {
+	while ((grp = getgrent ()) != NULL) {
 		if (is_on_list (grp->gr_mem, member)) {
-			if (groups++)
-				putchar (' ');
+			if (0 != groups) {
+				(void) putchar (' ');
+			}
+			groups++;
 
-			printf ("%s", grp->gr_name);
-			if (grp->gr_gid == pwd->pw_gid)
-				flag = 1;
+			(void) printf ("%s", grp->gr_name);
+			if (grp->gr_gid == pwd->pw_gid) {
+				flag = true;
+			}
 		}
 	}
 	endgrent ();
-	/* local, no need for xgetgrgid */
-	if (!flag && (grp = getgrgid (pwd->pw_gid))) {
-		if (groups++)
-			putchar (' ');
 
-		printf ("%s", grp->gr_name);
+	/* The user may not be in the list of members of its primary group */
+	if (!flag) {
+		grp = getgrgid (pwd->pw_gid); /* local, no need for xgetgrgid */
+		if (NULL != grp) {
+			if (0 != groups) {
+				(void) putchar (' ');
+			}
+			groups++;
+
+			(void) printf ("%s", grp->gr_name);
+		}
 	}
-	if (groups)
-		putchar ('\n');
+
+	if (0 != groups) {
+		(void) putchar ('\n');
+	}
 }
 
 /*
@@ -98,7 +111,7 @@
 #ifdef HAVE_GETGROUPS
 	int ngroups;
 	GETGROUPS_T *groups;
-	int pri_grp;
+	int pri_grp; /* TODO: should be GETGROUPS_T */
 	int i;
 #else
 	char *logname;
@@ -109,9 +122,9 @@
 #ifdef HAVE_GETGROUPS
 	groups = (GETGROUPS_T *) malloc (sys_ngroups * sizeof (GETGROUPS_T));
 #endif
-	setlocale (LC_ALL, "");
-	bindtextdomain (PACKAGE, LOCALEDIR);
-	textdomain (PACKAGE);
+	(void) setlocale (LC_ALL, "");
+	(void) bindtextdomain (PACKAGE, LOCALEDIR);
+	(void) textdomain (PACKAGE);
 
 	/*
 	 * Get the program name so that error messages can use it.
@@ -141,48 +154,58 @@
 		 * The groupset includes the primary group as well.
 		 */
 		pri_grp = getegid ();
-		for (i = 0; i < ngroups; i++)
-			if (pri_grp == (int) groups[i])
+		for (i = 0; i < ngroups; i++) {
+			if (pri_grp == (int) groups[i]) {
 				break;
+			}
+		}
 
-		if (i != ngroups)
+		if (i != ngroups) {
 			pri_grp = -1;
+		}
 
 		/*
 		 * Print out the name of every group in the current group
 		 * set. Unknown groups are printed as their decimal group ID
 		 * values.
 		 */
-		if (pri_grp != -1) {
+		if (-1 != pri_grp) {
 			struct group *gr;
 			/* local, no need for xgetgrgid */
-			if ((gr = getgrgid (pri_grp)))
-				printf ("%s", gr->gr_name);
-			else
-				printf ("%d", pri_grp);
+			gr = getgrgid (pri_grp);
+			if (NULL != gr) {
+				(void) printf ("%s", gr->gr_name);
+			} else {
+				(void) printf ("%d", pri_grp);
+			}
 		}
 
 		for (i = 0; i < ngroups; i++) {
 			struct group *gr;
-			if (i || pri_grp != -1)
-				putchar (' ');
+			if ((0 != i) || (-1 != pri_grp)) {
+				(void) putchar (' ');
+			}
 
 			/* local, no need for xgetgrgid */
-			if ((gr = getgrgid (groups[i])))
-				printf ("%s", gr->gr_name);
-			else
-				printf ("%ld", (long) groups[i]);
+			gr = getgrgid (groups[i]);
+			if (NULL != gr) {
+				(void) printf ("%s", gr->gr_name);
+			} else {
+				(void) printf ("%ld", (long) groups[i]);
+			}
 		}
-		putchar ('\n');
+		(void) putchar ('\n');
 #else
 		/*
 		 * This system does not have the getgroups() system call, so
 		 * I must check the groups file directly.
 		 */
-		if ((logname = getlogin ()))
+		logname = getlogin ();
+		if (NULL != logname) {
 			print_groups (logname);
-		else
+		} else {
 			exit (1);
+		}
 #endif
 	} else {
 
@@ -194,3 +217,4 @@
 	}
 	exit (0);
 }
+




More information about the Pkg-shadow-commits mailing list