This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
incorrect static char * assumption(?)
- To: gcc-bugs at gcc dot gnu dot org
- Subject: incorrect static char * assumption(?)
- From: Richard <blackw at sfu dot ca>
- Date: Tue, 07 Mar 2000 09:35:00 -0800
- Reply-To: blackw at sfu dot ca
egcs-2.91.66 appears to be making an erroneous assumption about the
contents of a static char * within a single printf() call.
SYMPTOM:
#include <stdio.h>
#include <string.h>
char newstring[5];
int main(void);
char *output(char *);
int main()
{
printf ("%s %s\n", output("this"), output("that"));
printf ("%s\n", output("this"));
printf ("%s\n", output("that"));
return 0;
}
char *output(char *string)
{
strcpy(newstring, string);
return newstring;
}
Output from the program:
this this
this
that
Obviously the first line of output should read:
this that
It appears the compiler is making the assumption that because the
function output() returns the same char *, it will contain the same
value for each call WITHIN a single printf() call. However, it does not
make this assumption BETWEEN printf() calls.
Cheers,
Richard
VERSION:
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
Red Hat 6.1
COMPILER INVOCATION:
g++ testme.cc -o testme
MACHINE:
Dell - Intel P133
GCC BUILD OPTIONS:
Unknown. Binaries installed from RedHat RPM