possible bug in YDL?


Subject: possible bug in YDL?
From: A Scottedward Hodel (a.s.hodel@Eng.Auburn.EDU)
Date: Sun Jun 18 2000 - 16:08:26 MDT


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!)

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;
}

-- 
A S Hodel Assoc. Prof. Dept Elect and Computer Eng, Auburn Univ,AL 36849-5201
On leave at NASA Marshall Space Flight Center (256) 544-1426
Address until 31 July 2000:Mail Code TD-55, MSFC, Alabama, 35812
http://www.eng.auburn.edu/~scotte



This archive was generated by hypermail 2a24 : Sun Jun 18 2000 - 16:14:34 MDT