* 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

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