[Pkg-shadow-commits] r2114 - in upstream/trunk: . lib

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Tue Jun 10 20:27:18 UTC 2008


Author: nekral-guest
Date: 2008-06-10 20:27:16 +0000 (Tue, 10 Jun 2008)
New Revision: 2114

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/lib/commonio.c
Log:
	* lib/commonio.c: Add brackets and parenthesis.
	* lib/commonio.c: Check the result of fgets().
	* lib/commonio.c: Avoid implicit conversion of pointers to
	booleans.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-06-10 20:02:47 UTC (rev 2113)
+++ upstream/trunk/ChangeLog	2008-06-10 20:27:16 UTC (rev 2114)
@@ -1,5 +1,12 @@
 2008-06-10  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* lib/commonio.c: Add brackets and parenthesis.
+	* lib/commonio.c: Check the result of fgets().
+	* lib/commonio.c: Avoid implicit conversion of pointers to
+	booleans.
+
+2008-06-10  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* lib/prototypes.h: Fix the prototypes to match earlier changes.
 
 2008-06-10  Nicolas François  <nicolas.francois at centraliens.net>

Modified: upstream/trunk/lib/commonio.c
===================================================================
--- upstream/trunk/lib/commonio.c	2008-06-10 20:02:47 UTC (rev 2113)
+++ upstream/trunk/lib/commonio.c	2008-06-10 20:27:16 UTC (rev 2114)
@@ -97,11 +97,13 @@
 {
 	struct stat sb;
 
-	if (stat (file, &sb) != 0)
+	if (stat (file, &sb) != 0) {
 		return 0;
+	}
 
-	if (sb.st_nlink != 2)
+	if (sb.st_nlink != 2) {
 		return 0;
+	}
 
 	return 1;
 }
@@ -177,7 +179,7 @@
 
 
 static FILE *fopen_set_perms (const char *name, const char *mode,
-			      const struct stat *sb)
+                              const struct stat *sb)
 {
 	FILE *fp;
 	mode_t mask;
@@ -190,19 +192,23 @@
 	}
 
 #ifdef HAVE_FCHOWN
-	if (fchown (fileno (fp), sb->st_uid, sb->st_gid) != 0)
+	if (fchown (fileno (fp), sb->st_uid, sb->st_gid) != 0) {
 		goto fail;
+	}
 #else
-	if (chown (name, sb->st_mode) != 0)
+	if (chown (name, sb->st_mode) != 0) {
 		goto fail;
+	}
 #endif
 
 #ifdef HAVE_FCHMOD
-	if (fchmod (fileno (fp), sb->st_mode & 0664) != 0)
+	if (fchmod (fileno (fp), sb->st_mode & 0664) != 0) {
 		goto fail;
+	}
 #else
-	if (chmod (name, sb->st_mode & 0664) != 0)
+	if (chmod (name, sb->st_mode & 0664) != 0) {
 		goto fail;
+	}
 #endif
 	return fp;
 
@@ -221,8 +227,9 @@
 	int c;
 	mode_t mask;
 
-	if (fstat (fileno (fp), &sb) != 0)
+	if (fstat (fileno (fp), &sb) != 0) {
 		return -1;
+	}
 
 	mask = umask (077);
 	bkfp = fopen (backup, "w");
@@ -235,8 +242,9 @@
 	c = 0;
 	if (fseek (fp, 0, SEEK_SET) == 0) {
 		while ((c = getc (fp)) != EOF) {
-			if (putc (c, bkfp) == EOF)
+			if (putc (c, bkfp) == EOF) {
 				break;
+			}
 		}
 	}
 	if ((c != EOF) || (ferror (fp) != 0) || (fflush (bkfp) != 0)) {
@@ -262,11 +270,13 @@
 		p = db->head;
 		db->head = p->next;
 
-		if (NULL != p->line)
+		if (NULL != p->line) {
 			free (p->line);
+		}
 
-		if (NULL != p->eptr)
+		if (NULL != p->eptr) {
 			db->ops->free (p->eptr);
+		}
 
 		free (p);
 	}
@@ -292,8 +302,9 @@
 	char file[1024];
 	char lock[1024];
 
-	if (db->locked)
+	if (db->locked) {
 		return 1;
+	}
 
 	snprintf (file, sizeof file, "%s.%lu",
 	          db->filename, (unsigned long) getpid ());
@@ -320,13 +331,15 @@
 	 * If it succeeds, call *_lock() only once
 	 * (no retries, it should always succeed).
 	 */
-	if (lock_count == 0) {
-		if (lckpwdf () == -1)
+	if (0 == lock_count) {
+		if (lckpwdf () == -1) {
 			return 0;	/* failure */
+		}
 	}
 
-	if (commonio_lock_nowait (db) != 0)
+	if (commonio_lock_nowait (db) != 0) {
 		return 1;	/* success */
+	}
 
 	ulckpwdf ();
 	return 0;		/* failure */
@@ -344,8 +357,9 @@
 #define LOCK_SLEEP 1
 #endif
 	for (i = 0; i < LOCK_TRIES; i++) {
-		if (i > 0)
+		if (i > 0) {
 			sleep (LOCK_SLEEP);	/* delay between retries */
+		}
 		if (commonio_lock_nowait (db) != 0) {
 			return 1;	/* success */
 		}
@@ -385,8 +399,9 @@
 	if (db->isopen) {
 		db->readonly = true;
 		if (commonio_close (db) == 0) {
-			if (db->locked)
+			if (db->locked) {
 				dec_lock_count ();
+			}
 			return 0;
 		}
 	}
@@ -409,17 +424,19 @@
 {
 	p->next = NULL;
 	p->prev = db->tail;
-	if (!db->head)
+	if (NULL == db->head) {
 		db->head = p;
-	if (db->tail)
+	}
+	if (NULL != db->tail) {
 		db->tail->next = p;
+	}
 	db->tail = p;
 }
 
 
 static bool name_is_nis (const char *name)
 {
-	return (name[0] == '+' || name[0] == '-');
+	return (('+' == name[0]) || ('-' == name[0]));
 }
 
 
@@ -443,14 +460,15 @@
 	struct commonio_entry *p;
 
 	for (p = db->head; NULL != p; p = p->next) {
-		if (name_is_nis
-		    (p->eptr ? db->ops->getname (p->eptr) : p->line)) {
+		if (name_is_nis (p->eptr ? db->ops->getname (p->eptr)
+		                         : p->line)) {
 			newp->next = p;
 			newp->prev = p->prev;
-			if (NULL != p->prev)
+			if (NULL != p->prev) {
 				p->prev->next = newp;
-			else
+			} else {
 				db->head = newp;
+			}
 			p->prev = newp;
 			return;
 		}
@@ -476,7 +494,9 @@
 
 	mode &= ~O_CREAT;
 
-	if (db->isopen || (mode != O_RDONLY && mode != O_RDWR)) {
+	if (   db->isopen
+	    || (   (O_RDONLY != mode)
+	        && (O_RDWR != mode))) {
 		errno = EINVAL;
 		return 0;
 	}
@@ -496,7 +516,7 @@
 	 * created by commonio_close().  We have no entries to read yet.  --marekm
 	 */
 	if (NULL == db->fp) {
-		if (((flags & O_CREAT) != 0) && (errno == ENOENT)) {
+		if (((flags & O_CREAT) != 0) && (ENOENT == errno)) {
 			db->isopen = true;
 			return 1;
 		}
@@ -522,8 +542,8 @@
 	}
 
 	while (db->ops->fgets (buf, buflen, db->fp) == buf) {
-		while (((cp = strrchr (buf, '\n')) == NULL) &&
-		       (feof (db->fp) == 0)) {
+		while (   ((cp = strrchr (buf, '\n')) == NULL)
+		       && (feof (db->fp) == 0)) {
 			int len;
 
 			buflen += BUFLEN;
@@ -533,7 +553,9 @@
 			}
 			buf = cp;
 			len = strlen (buf);
-			db->ops->fgets (buf + len, buflen - len, db->fp);
+			if (db->ops->fgets (buf + len, buflen - len, db->fp) == NULL) {
+				goto cleanup_buf;
+			}
 		}
 		cp = strrchr (buf, '\n');
 		if (NULL != cp) {
@@ -616,15 +638,18 @@
 	struct commonio_entry **entries, *ptr;
 	int n = 0, i;
 
-	for (ptr = db->head; ptr; ptr = ptr->next)
+	for (ptr = db->head; NULL != ptr; ptr = ptr->next) {
 		n++;
+	}
 
-	if (n <= 1)
+	if (n <= 1) {
 		return 0;
+	}
 
 	entries = malloc (n * sizeof (struct commonio_entry *));
-	if (entries == NULL)
+	if (entries == NULL) {
 		return -1;
+	}
 
 	n = 0;
 	for (ptr = db->head; NULL != ptr; ptr = ptr->next) {
@@ -658,8 +683,9 @@
 	struct commonio_entry *head = NULL, *pw_ptr, *spw_ptr;
 	const char *name;
 
-	if (!shadow || !shadow->head)
+	if ((NULL == shadow) || (NULL == shadow->head)) {
 		return 0;
+	}
 
 	for (pw_ptr = passwd->head; NULL != pw_ptr; pw_ptr = pw_ptr->next) {
 		if (NULL == pw_ptr->eptr) {
@@ -714,7 +740,7 @@
 			if (db->ops->put (eptr, db->fp) != 0) {
 				return -1;
 			}
-		} else if (p->line) {
+		} else if (NULL != p->line) {
 			if (db->ops->fputs (p->line, db->fp) == EOF) {
 				return -1;
 			}
@@ -842,7 +868,7 @@
 		if (setfscreatecon (old_context) < 0) {
 			errors++;
 		}
-		if (old_context != NULL) {
+		if (NULL != old_context) {
 			freecon (old_context);
 			old_context = NULL;
 		}
@@ -861,13 +887,14 @@
 	struct commonio_entry *p;
 	void *ep;
 
-	if (NULL == pos)
+	if (NULL == pos) {
 		return NULL;
+	}
 
 	for (p = pos; NULL != p; p = p->next) {
 		ep = p->eptr;
-		if ((NULL != ep) &&
-		    (strcmp (db->ops->getname (ep), name) == 0)) {
+		if (   (NULL != ep)
+		    && (strcmp (db->ops->getname (ep), name) == 0)) {
 			break;
 		}
 	}




More information about the Pkg-shadow-commits mailing list