thewalt@RITZ.ce.cmu.edu (Chris Thewalt) (10/19/89)
Hello. I am using gcc 1.36 on a MicroVAX running Ultrix 2.2. I tried
to compile the following simple program without the -fwritable strings
and get a bus error, but it works with the flag. I don't quite
understand this since I am not attempting to write into any string
constants. A script of the session follows:
Script started on Thu Oct 19 12:41:58 1989
% cat ttt.c
#include <stdio.h>
main()
{
char *p[3], w[27], *q = w;
register int i;
sscanf("plan-plan","%s",p[0] = q);
q += strlen(q) + 1;
sscanf("lin-lin", "%s",p[1] = q);
q += strlen(q) + 1;
sscanf("lin-plan", "%s",p[2] = q);
for(i=0;i < 3;++i)
printf("%s\n",p[i]);
}
% gcc -v -o ttt ttt.c
gcc version 1.36
/usr/misc/.gnu/lib/compilers/gcc-cpp -v -undef -D__GNUC__ -Dvax -Dunix -D__vax__ -D__unix__ ttt.c /usr/tmp/cc022254.cpp
GNU CPP version 1.36
/usr/misc/.gnu/lib/compilers/gcc-cc1 /usr/tmp/cc022254.cpp -quiet -dumpbase ttt.c -version -o /usr/tmp/cc022254.s
GNU C version 1.36 (vax) compiled by GNU C version 1.36.
default target switches: -munix
as -o ttt.o /usr/tmp/cc022254.s
ld -o ttt /lib/crt0.o ttt.o /usr/misc/.gnu/lib/compilers/gcc-gnulib -lc
% ttt
Bus error
% gcc -fwritable-strings -v -o ttt ttt.c
gcc version 1.36
/usr/misc/.gnu/lib/compilers/gcc-cpp -v -undef -D__GNUC__ -Dvax -Dunix -D__vax__ -D__unix__ ttt.c /usr/tmp/cc022260.cpp
GNU CPP version 1.36
/usr/misc/.gnu/lib/compilers/gcc-cc1 /usr/tmp/cc022260.cpp -quiet -dumpbase ttt.c -fwritable-strings -version -o /usr/tmp/cc022260.s
GNU C version 1.36 (vax) compiled by GNU C version 1.36.
default target switches: -munix
as -o ttt.o /usr/tmp/cc022260.s
ld -o ttt /lib/crt0.o ttt.o /usr/misc/.gnu/lib/compilers/gcc-gnulib -lc
% ttt
plan-plan
lin-lin
lin-plan
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Christopher Robin Thewalt These opinions are not necessarily
thewalt@ce.cmu.edu shared by my employer...
Carnegie Mellon University
thewalt@RITZ.ce.cmu.edu (Chris Thewalt) (10/22/89)
In a previous article I wrote: > Hello. I am using gcc 1.36 on a MicroVAX running Ultrix 2.2. I tried > to compile the following simple program without the -fwritable strings > and get a bus error, but it works with the flag. I don't quite > understand this since I am not attempting to write into any string > constants. A script of the session follows: Thanks to the many people who responded and told me that Ultrix' sscanf (and many other Unix variants) attempts to scribble into the argument string (faking an ungetc). -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Christopher Robin Thewalt These opinions are not necessarily thewalt@ce.cmu.edu shared by my employer... Carnegie Mellon University