Hi,
I think, vasprintf should do an realloc in any case:
int
AG_Vasprintf(char **ret, const char *fmt, va_list ap)
{
#ifndef HAVE_VASPRINTF
char *buf;
int size;
size_t buflen;
buflen = strlen(fmt) + 10240; /* XXX */
if ((buf = TryMalloc(buflen)) == NULL) {
return (-1);
}
size = vsprintf(buf, fmt, ap);
if ((size_t)size <= buflen) {
*ret = buf;
return (size);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Before returning I suggest also a TryRealloc(buf,size+1) for memory
contraint (embedded) systems.
-------------------------------------
}
if ((buf = TryRealloc(buf, size+1)) == NULL) {
Free(buf);
return (-1);
}
size = vsprintf(buf, fmt, ap);
*ret = buf;
return (size);
#else /* !HAVE_VASPRINTF */
if (vasprintf(ret, fmt, ap) == -1) {
AG_SetError("Out of memory");
return (-1);
}
return (0);
#endif /* HAVE_VASPRINTF */
}
--
42Bastian
+
| http://www.sciopta.com
| Fastest direct message passing kernel.
| IEC61508 certified.
+
_______________________________________________
Agar mailing list
[email protected]
http://libagar.org/lists.html