xasprintf: exit if return value of vsnprintf is invalid

This commit is contained in:
William Hubbs 2018-02-10 14:09:22 -06:00
parent 4616f8f809
commit 68b9b0bc2a

View File

@ -158,15 +158,12 @@ _unused static int xasprintf(char **strp, const char *fmt, ...)
va_start(ap, fmt);
len = vsnprintf(ret, len + 1, fmt, ap);
va_end(ap);
if (len >= memlen) {
/* Give up! */
free(ret);
return -1;
}
}
if (len < 0) {
if (len < 0 || len >= memlen) {
/* Give up! */
fprintf(stderr, "xasprintf: unable to format a buffer\n");
free(ret);
return -1;
exit(1);
}
*strp = ret;
return len;