[Pkg-shadow-commits] r2787 - in upstream/trunk: . libmisc

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Fri Apr 24 22:46:06 UTC 2009


Author: nekral-guest
Date: 2009-04-24 22:46:06 +0000 (Fri, 24 Apr 2009)
New Revision: 2787

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/libmisc/loginprompt.c
   upstream/trunk/libmisc/mail.c
   upstream/trunk/libmisc/setupenv.c
Log:
	* libmisc/setupenv.c: Prefer snprintf to sprintf, even if a small
	context indicates no issues.
	* libmisc/setupenv.c: Avoid implicit conversion of pointers to
	booleans.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-04-24 22:27:58 UTC (rev 2786)
+++ upstream/trunk/ChangeLog	2009-04-24 22:46:06 UTC (rev 2787)
@@ -1,5 +1,12 @@
 2009-04-25  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* libmisc/setupenv.c: Prefer snprintf to sprintf, even if a small
+	context indicates no issues.
+	* libmisc/setupenv.c: Avoid implicit conversion of pointers to
+	booleans.
+
+2009-04-25  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* libmisc/loginprompt.c: Prefer snprintf to sprintf, even if a
 	small context indicates no issues.
 

Modified: upstream/trunk/libmisc/loginprompt.c
===================================================================
--- upstream/trunk/libmisc/loginprompt.c	2009-04-24 22:27:58 UTC (rev 2786)
+++ upstream/trunk/libmisc/loginprompt.c	2009-04-24 22:46:06 UTC (rev 2787)
@@ -34,6 +34,7 @@
 
 #ident "$Id$"
 
+#include <assert.h>
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
@@ -157,8 +158,10 @@
 				envp[envc] = nvar;
 			} else {
 				size_t len = strlen (nvar) + 32;
+				int wlen;
 				envp[envc] = xmalloc (len);
-				snprintf (envp[envc], len, "L%d=%s", count++, nvar);
+				wlen = snprintf (envp[envc], len, "L%d=%s", count++, nvar);
+				assert (wlen == (int) len -1);
 			}
 		}
 		set_env (envc, envp);

Modified: upstream/trunk/libmisc/mail.c
===================================================================
--- upstream/trunk/libmisc/mail.c	2009-04-24 22:27:58 UTC (rev 2786)
+++ upstream/trunk/libmisc/mail.c	2009-04-24 22:46:06 UTC (rev 2787)
@@ -58,9 +58,12 @@
 	if (NULL != mailbox) {
 		char *newmail;
 		size_t len = strlen (mailbox) + 5;
+		int wlen;
 
 		newmail = xmalloc (len);
-		snprintf (newmail, len, "%s/new", mailbox);
+		wlen = snprintf (newmail, len, "%s/new", mailbox);
+		assert (wlen == (int) len - 1);
+
 		if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) {
 			if (statbuf.st_mtime > statbuf.st_atime) {
 				free (newmail);

Modified: upstream/trunk/libmisc/setupenv.c
===================================================================
--- upstream/trunk/libmisc/setupenv.c	2009-04-24 22:27:58 UTC (rev 2786)
+++ upstream/trunk/libmisc/setupenv.c	2009-04-24 22:46:06 UTC (rev 2787)
@@ -38,6 +38,7 @@
 
 #ident "$Id$"
 
+#include <assert.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
@@ -52,9 +53,13 @@
 addenv_path (const char *varname, const char *dirname, const char *filename)
 {
 	char *buf;
+	size_t len = strlen (dirname) + strlen (filename) + 2;
+	int wlen;
 
-	buf = xmalloc (strlen (dirname) + strlen (filename) + 2);
-	sprintf (buf, "%s/%s", dirname, filename);
+	buf = xmalloc (len);
+	wlen = snprintf (buf, len, "%s/%s", dirname, filename);
+	assert (wlen == (int) len - 1);
+
 	addenv (varname, buf);
 	free (buf);
 }
@@ -66,12 +71,14 @@
 	char *cp, *name, *val;
 
 	fp = fopen (filename, "r");
-	if (!fp)
+	if (NULL == fp) {
 		return;
+	}
 	while (fgets (buf, sizeof buf, fp) == buf) {
 		cp = strrchr (buf, '\n');
-		if (!cp)
+		if (NULL == cp) {
 			break;
+		}
 		*cp = '\0';
 
 		cp = buf;




More information about the Pkg-shadow-commits mailing list