Ensure asprintf'd string is NUL-terminated

PUBLISHED_FROM=b4062780d22be37acdbecd86e5951245e2908ff8
This commit is contained in:
Deomid Ryabkov 2016-06-22 17:12:36 +01:00 committed by Cesanta Bot
parent e3a9c6afb4
commit b535cb319a

View File

@ -10238,13 +10238,13 @@ int asprintf(char **strp, const char *fmt, ...) {
va_end(ap);
if (len > 0) {
*strp = realloc(*strp, len);
*strp = realloc(*strp, len + 1);
if (*strp == NULL) return -1;
}
if (len >= BUFSIZ) {
va_start(ap, fmt);
len = vsnprintf(*strp, len, fmt, ap);
len = vsnprintf(*strp, len + 1, fmt, ap);
va_end(ap);
}