* 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.
This commit is contained in:
nekral-guest 2009-04-24 22:46:06 +00:00
parent 42e72c418d
commit 7646230de2
4 changed files with 26 additions and 6 deletions

View File

@ -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

View 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);

View 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);

View 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;