Wolfgang Rohdewald wrote:
since asprintf leads to segfaults if feeded with incorrect UTF-8 characters,
It's not asprintf that segfaults but the call to free uninitialized memory afterwards.
I wanted to write a wrapper function which would then check the return value of asprintf. However I have a problem with the variable argument list and the va_* macros. Using gdb shows that, in the following example, in
res=asprintf (strp, fmt, ap);
ap is interpreted not as a list of arguments but as an integer.
use vasprintf
int msprintf(char **strp, const char *fmt, ...) { va_list ap; int res; va_start (ap, fmt); res=asprintf (strp, fmt, ap); va_end (ap); }
Even if you use vasprintf to make the function actually work you still need to check the return value of vasprintf otherwise this wrapper would be kind of useless.
cu Ludwig