Skip to contentSkip to conversation

Nested stdarg broken?

DISCUSSION Bob Toxen 2 participants 2 messages Oct 26, 1999 – Oct 27, 1999

lore
Share & tools
lore

Bob Toxen

author
#0 lore raw

My application uses stdarg (#include <stdarg.h>, va_start, and friends) in a function that then calls vfprintf which also uses stdarg.

The variable args get garbled by the time they get to vfprintf. The fmt arg does not get garbled.

Note that the documentation specifies that this should work. My application works fine on Linux on Intel and other platforms. The PowerPC is the first big endian platform but I am quite sure that the bug is not in my code.

My code (simplified) looks like

#include <stdio.h>
#include <stdarg.h>

logmsg(int out, const char *fmt, ...)

{
	FILE	*fp;
	char	*p;
	int	ret	= 0;
	char	buf[512];
	va_list	ap;	/* May need to be last arg. */

	va_start(ap, fmt);
	fflush(stdout);		/* Flush "the other" output. */
	fp = fopen(logfile, "a");
	if (!fp || vfprintf(fp, fmt, ap) < 1)
		ret = -1;
	if (fp && fclose(fp) == EOF)
		ret = -1;
	va_end(ap);
	return ret;
}

THANKS for any insight. Presently I'm IFDEFing it to not use stdargs on the PowerPC platform.

Bob Toxen
[email protected]
Error #152, Windows not found: (C)heer, (P)arty, (D)ance

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 6 lines · Bob Toxen

My application uses stdarg (#include <stdarg.h>, va_start, and friends) in a function that then calls vfprintf which also uses stdarg.

The variable args get garbled by the time they get to vfprintf. The fmt arg does not get garbled.

Here's what you can read at
http://egcs.cygnus.com/gcc-2.95/gcc-2.95.1.html
under section "Platform specific bugfixes and improvements"
Fix varargs/stdarg code generation bug for rs6000/ppc svr4
targets.
Maybe this helps, maybe not.

Regards,
-velco

btw, 2.95.2 is out

-velco

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/