__printf_2_0 unsigned xvasprintf(char **result, const char *fmt, va_list ap)
{
int ret;
- size_t size;
+ size_t size = 150;
va_list aq;
+ *result = para_malloc(size + 1);
va_copy(aq, ap);
- ret = vsnprintf(NULL, 0, fmt, aq);
+ ret = vsnprintf(*result, size, fmt, aq);
va_end(aq);
assert(ret >= 0);
+ if (ret < size) /* OK */
+ return ret;
size = ret + 1;
- *result = para_malloc(size);
+ *result = para_realloc(*result, size);
va_copy(aq, ap);
ret = vsnprintf(*result, size, fmt, aq);
va_end(aq);