* 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:
parent
42e72c418d
commit
7646230de2
@ -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>
|
2009-04-25 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* libmisc/loginprompt.c: Prefer snprintf to sprintf, even if a
|
* libmisc/loginprompt.c: Prefer snprintf to sprintf, even if a
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -157,8 +158,10 @@ void login_prompt (const char *prompt, char *name, int namesize)
|
|||||||
envp[envc] = nvar;
|
envp[envc] = nvar;
|
||||||
} else {
|
} else {
|
||||||
size_t len = strlen (nvar) + 32;
|
size_t len = strlen (nvar) + 32;
|
||||||
|
int wlen;
|
||||||
envp[envc] = xmalloc (len);
|
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);
|
set_env (envc, envp);
|
||||||
|
@ -58,9 +58,12 @@ void mailcheck (void)
|
|||||||
if (NULL != mailbox) {
|
if (NULL != mailbox) {
|
||||||
char *newmail;
|
char *newmail;
|
||||||
size_t len = strlen (mailbox) + 5;
|
size_t len = strlen (mailbox) + 5;
|
||||||
|
int wlen;
|
||||||
|
|
||||||
newmail = xmalloc (len);
|
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 (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) {
|
||||||
if (statbuf.st_mtime > statbuf.st_atime) {
|
if (statbuf.st_mtime > statbuf.st_atime) {
|
||||||
free (newmail);
|
free (newmail);
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -52,9 +53,13 @@ static void
|
|||||||
addenv_path (const char *varname, const char *dirname, const char *filename)
|
addenv_path (const char *varname, const char *dirname, const char *filename)
|
||||||
{
|
{
|
||||||
char *buf;
|
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);
|
addenv (varname, buf);
|
||||||
free (buf);
|
free (buf);
|
||||||
}
|
}
|
||||||
@ -66,12 +71,14 @@ static void read_env_file (const char *filename)
|
|||||||
char *cp, *name, *val;
|
char *cp, *name, *val;
|
||||||
|
|
||||||
fp = fopen (filename, "r");
|
fp = fopen (filename, "r");
|
||||||
if (!fp)
|
if (NULL == fp) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
while (fgets (buf, sizeof buf, fp) == buf) {
|
while (fgets (buf, sizeof buf, fp) == buf) {
|
||||||
cp = strrchr (buf, '\n');
|
cp = strrchr (buf, '\n');
|
||||||
if (!cp)
|
if (NULL == cp) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
|
|
||||||
cp = buf;
|
cp = buf;
|
||||||
|
Loading…
Reference in New Issue
Block a user