]> granicus.if.org Git - shadow/commitdiff
* libmisc/setupenv.c: Prefer snprintf to sprintf, even if a small
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 24 Apr 2009 22:46:06 +0000 (22:46 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 24 Apr 2009 22:46:06 +0000 (22:46 +0000)
context indicates no issues.
* libmisc/setupenv.c: Avoid implicit conversion of pointers to
booleans.

ChangeLog
libmisc/loginprompt.c
libmisc/mail.c
libmisc/setupenv.c

index dc7c4307b7c532429fb23da2a1368877b2084774..0f98f82c060ed01c88d1bf95641c72244d5fc7dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-04-25  Nicolas François  <nicolas.francois@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@centraliens.net>
 
        * libmisc/loginprompt.c: Prefer snprintf to sprintf, even if a
index bcc42b36a180ae90b75ddc71d4ad3ffaa8f1d4a4..3ca893887d4f784573eae4dac488c135916a58f7 100644 (file)
@@ -34,6 +34,7 @@
 
 #ident "$Id$"
 
+#include <assert.h>
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
@@ -157,8 +158,10 @@ void login_prompt (const char *prompt, char *name, int namesize)
                                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);
index 5b70c73c351852b001aff9c3cec2b29e64197292..cf4f13ee16df4488f14e76fd0464fd4f3becc78c 100644 (file)
@@ -58,9 +58,12 @@ void mailcheck (void)
        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);
index 7a6651366b2769e9ec193cfe9868a2c60376d25b..693881369e2d0e13f29e86fe8321d79da2be4e2b 100644 (file)
@@ -38,6 +38,7 @@
 
 #ident "$Id$"
 
+#include <assert.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
@@ -52,9 +53,13 @@ static void
 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 (len);
+       wlen = snprintf (buf, len, "%s/%s", dirname, filename);
+       assert (wlen == (int) len - 1);
 
-       buf = xmalloc (strlen (dirname) + strlen (filename) + 2);
-       sprintf (buf, "%s/%s", dirname, filename);
        addenv (varname, buf);
        free (buf);
 }
@@ -66,12 +71,14 @@ static void read_env_file (const char *filename)
        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;