Check the return value from asprintf().

This is actually redundant, because we already check the pointer, which is NULL if and only if asprintf() fails and returns < 0, but the version of gcc used by Travis CI insists.  I have not been able to reproduce the issue on any other platform available to me.
This commit is contained in:
Dag-Erling Smørgrav 2016-09-18 22:18:02 +02:00
parent 7a2defcf42
commit eab216c06a

View file

@ -50,7 +50,7 @@ struct t_file *
t_fopen(const char *filename)
{
struct t_file *tf;
int fd;
int fd, ret;
if ((tf = calloc(sizeof *tf, 1)) == NULL)
err(1, "%s(): calloc()", __func__);
@ -58,9 +58,9 @@ t_fopen(const char *filename)
if ((tf->name = strdup(filename)) == NULL)
err(1, "%s(): strdup()", __func__);
} else {
asprintf(&tf->name, "%s.%lu.%p.tmp",
ret = asprintf(&tf->name, "%s.%lu.%p.tmp",
t_progname, (unsigned long)getpid(), (void *)tf);
if (tf->name == NULL)
if (ret < 0 || tf->name == NULL)
err(1, "%s(): asprintf()", __func__);
}
if ((fd = open(tf->name, O_RDWR|O_CREAT|O_TRUNC, 0600)) < 0)