Check return value from asprintf instead of string != NULL since it

undefined behavior on Linux. From Björn Sandell


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16224 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2005-10-22 17:17:44 +00:00
parent af8272f96c
commit d448f74010
2 changed files with 9 additions and 6 deletions

View File

@@ -1582,6 +1582,7 @@ env_init(void)
|| strncmp((char *)ep->value, "unix:", 5) == 0)) {
char hbuf[256+1];
char *cp2 = strchr((char *)ep->value, ':');
int error;
/* XXX - should be k_gethostname? */
gethostname(hbuf, 256);
@@ -1590,7 +1591,6 @@ env_init(void)
/* If this is not the full name, try to get it via DNS */
if (strchr(hbuf, '.') == 0) {
struct addrinfo hints, *ai, *a;
int error;
memset (&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
@@ -1608,10 +1608,12 @@ env_init(void)
}
}
asprintf (&cp, "%s%s", hbuf, cp2);
error = asprintf (&cp, "%s%s", hbuf, cp2);
if (error != -1) {
free (ep->value);
ep->value = (unsigned char *)cp;
}
}
/*
* If USER is not defined, but LOGNAME is, then add
* USER with the value from LOGNAME. By default, we

View File

@@ -244,9 +244,10 @@ init_words (int argc, char **argv)
appres.file = argv[i];
i++;
} else {
asprintf (&appres.file,
int ret;
ret = asprintf (&appres.file,
"%s/.msgfile", getenv("HOME"));
if (appres.file == NULL)
if (ret == -1)
errx (1, "cannot allocate memory for message");
}
} else if(strcmp(argv[i], "--version") == 0) {