diff --git a/src/common/asprintf.c b/src/common/asprintf.c --- a/src/common/asprintf.c +++ b/src/common/asprintf.c @@ -28,14 +28,22 @@ int _distren_asprintf(char **strp, const size_t needed; va_start(ap, fmt); + /** + The return value is the size of the string that snprintf wants + to write excluding the terminating '\0' + */ needed = vsnprintf(NULL, 0, fmt, ap); /*< returns the number of bytes to allocate */ va_end(ap); - + + needed ++; *strp = malloc(needed); if(!*strp) return -1; va_start(ap, fmt); + /** + The n argument must specify the size of the allocated space + */ needed = vsnprintf(*strp, needed, fmt, ap); va_end(ap);