[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#107081: PowerPC: reuse same va_list more that once failed



> > And stdarg doesn't have these issues? The problem is that va_list isn't a
> > pointer on powerpc so it gets modified across calls. Saving the initial
> > va_list state and restoring it before reuse should solve this for varargs.
> 
> No, stdarg and vararg are both implemented in gcc, so the bug is not in
> glibc. Which is why I reassigned it to gcc. I agree with your bug, since
> on sparc it works as expected. It was just filed against the wrong
> package.

This is not a bug in gcc, or glibc. It's a feature of the PPC
va_list implementation, mandated by the PPC ABI that we
need to follow (otherwise all sort of hell breaks loose). 

The following fragment of code just happens to work OK for other
architectures, but it is bogus nonetheless: 

void vlog_and_print(char *fmt, va_list ap)
{
        fprintf (stdout, "First\n"); fflush(stdout);
        vfprintf (stdout, fmt, ap); fflush(stdout);

// ap has been EXHAUSTED at this point, for crying out loud!

        fprintf (stdout, "Second\n"); fflush(stdout);
// so WTF are you trying to print now? 
        vfprintf (stdout, fmt, ap); fflush(stdout);
}

Try this:

void vlog_and_print(char *fmt, va_list ap)
{
	va_list va_scratch;
	va_copy (va_scratch, ap);

        fprintf (stdout, "First\n"); fflush(stdout);
        vfprintf (stdout, fmt, ap); fflush(stdout);

	va_copy (ap, va_scratch);

        fprintf (stdout, "Second\n"); fflush(stdout);
        vfprintf (stdout, fmt, ap); fflush(stdout);
}


	Michael



Reply to: