[vdr] trouble with asprintf

Ludwig Nussel ludwig.nussel at suse.de
Mon Feb 11 09:07:12 CET 2008

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.


 (o_   Ludwig Nussel
 V_/_  http://www.suse.de/
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)

More information about the vdr mailing list