Re: possible bug in YDL?


Subject: Re: possible bug in YDL?
From: Jim Cole (greyleaf@yggdrasill.net)
Date: Mon Jun 19 2000 - 03:29:16 MDT


A Scottedward Hodel's bits of Sun, 18 Jun 2000 translated to:

>At first glance this looks like a gcc/gnu tools question, but the failure
>only occurs under YDL, so I thought I'd send it in here:
>
>The code fragment below works fine using gcc-29.5.2 on a Compaq Alpha, under
>cygwin on windows 95, and under machten Unix. (The last two using
>earlier versions of gcc.)
>
>The problem appears to be that a va_list cannot be used twice in
>the same subroutine. If someone else has the time to check this
>behavior, I'd appreciate it. (Better yet, if there's an easy patch
>to the va_start/va_end, va_args macros to make this code work properly,
>that would be great!)

I see the same thing as you when running your code with slightly newer
compiler (2.95.2-1k) and binutils (2.9.5.0.34-0a) packages. The problem
goes away if I run it under Linux with gcc 2.95.2 on an Intel machine.

But is your code really correct? The little experience I have had with
vararg stuff has always involved using va_arg to extract the arguments.
The man pages say something about the state of va_list being undefined
after a call to v*printf. But I am not sure if that only applies in the
context of needing to call va_end or whether it applies to any call
using a va_list. If you declare and start two va_list's, and hand one
to each v*printf, the problem goes away. Same goes for extracting with
va_arg and passing the arguments to printf/fprintf.

Jim

>
>Here's the code.
>
> /* Problem in YDL that does not occur with SunOS, Dec Unix, or
> * gnu tools under Machen Unix.
> *
> * Get a seg fault when executing line marked "MARKER B"
> * Program received signal SIGSEGV, Segmentation fault.
> * 0xff49454 in strlen () at soinit.c:59
> * (gdb) up
> * #1 0xff2d860 in _IO_vfprintf (s=0x10010a58,
> * format=0x1b6 <Address 0x1b6 out of bounds>, ap=0x7ffffc30)
> * at vfprintf.c:1259
> * 1259 vfprintf.c: No such file or directory.
> * (gdb) up
> * #2 0x10000680 in infmsg (format=0x1000082c "starting simulation %s")
> * at jnk.c:23
> * 23 vfprintf (log_file, format, args);
> * (gdb) print format
> * $2 = 0x1000082c "starting simulation %s"
> *
> * If comment out line marked MARKER A, the seg fault does not occur
> * YDL.
> */
>#include <stdio.h>
>#include <stdarg.h>
>
>FILE *log_file;
>char fname[] = "File name";
>int lnum = 6;
>
>void
>infmsg (char *format, ...)
>{
> va_list args; /* Arguments. */
>
> /* Write to standard out and to log file. */
> va_start (args, format);
> printf ("INF: ");
> fprintf (log_file, "INF: ");
> if (lnum != 0)
> {
> printf ("%s (%d) ", fname, lnum);
> fprintf (log_file, "%s (%d) ", fname, lnum);
> }
> vprintf (format, args); /* MARKER A */
> vfprintf (log_file, format, args); /* MARKER B */
>
> putchar ('\n');
> putc ('\n', log_file);
> va_end (args);
>}
>
>int main()
>{
> log_file = fopen("outfile","w");
> infmsg("starting simulation %s",fname);
> fclose(log_file);
> return 0;
>}
>



This archive was generated by hypermail 2a24 : Mon Jun 19 2000 - 03:16:33 MDT