On 10/17/07, Macy Gasp <[EMAIL PROTECTED]> wrote:
> Hi everybody,
>
> I'm experiencing a weird behaviour when using va_list with gcc 4.1.2
> on a x86_64 linux distribution.
>
> Below is my test program (yes, I know about the possible buffer
> overflows but please, bear with me, this is just a proof of concept):
>
> #include <stdio.h>
> #include <stdarg.h>
>
> int var(const char* fmt, ...)
> {
>     va_list args;
>     char buf[4096];
>
>     va_start(args, fmt);
>

--- no va_copy

>     vsprintf(buf, fmt, args);
>     fprintf(stderr,"\n[%s]", buf);
>
-- args is semi invalid here.

>     vsprintf(buf, fmt, args);
>     fprintf(stderr,"\n[%s]", buf);
>
>     va_end(args);
>
>     return 0;
> }

You forgot to call va_copy.

-- Pinski

Reply via email to