[gnu.gcc] GCC/stdio interaction

jack@cwi.nl (Jack Jansen) (12/02/88)

The following is probably not a bug in GCC, but in Ultrix (and maybe
other) stdio. However, gcc triggers the bug because it stores
strings in read-only space.

What happens is that the following program will dump core:
--------
main() {
    int i;
    short j;

    i = sscanf("1", "%hd", &j);
    printf("i=%d, j=%d\n", i, j);
}
---------
What happens is the following: sscanf sets up a dummy FILE * structure,
points the buffer/pointer to the argument string "1" and calls _doscan.

Doscan, however, will call ungetc() at some point. Ungetc will try to
stuff a character back into the input buffer. BANG!

Just thought I'd warn the rest of the net....
--
Fight war, not wars			| Jack Jansen, jack@cwi.nl
Destroy power, not people! -- Crass	| (or mcvax!jack)

weening@Gang-of-Four.Stanford.EDU (Joe Weening) (12/03/88)

In article <7747@boring.cwi.nl>, jack@cwi (Jack Jansen) writes:
>
>The following is probably not a bug in GCC, but in Ultrix (and maybe
>other) stdio. However, gcc triggers the bug because it stores
>strings in read-only space.
> ...

I encountered this when compiling the window manager "twm" for X11R3,
and it may happen on other X11 programs as well.  This was under Sun
OS 4.0, by the way.  Adding "-fwritable-strings" to the GCC options
avoids the problems, however.
--
Joe Weening                                Computer Science Dept.
weening@Gang-of-Four.Stanford.EDU          Stanford University