[gnu.gcc.bug] core dumper under GCC 1.30

bet@BENT.MC.DUKE.EDU (Bennett Todd) (10/19/88)

The following dumps core when compiled with gcc-1.30 on a Sun 3/60 running
SunOS 3.5, but not when compiled with the SunOS C compiler. It actually
dumps down in the bowels of stdio in the sscanf. It looks to me like
something or other in the run-time environment isn't beeing arranged to suit
sscanf. A friend (Ned Danieley, ndd@sunbar.mc.duke.edu) stumbled across it
recompiling an X application. We were running 1.29 at the time; I fetched
the diffs and brought us up to 1.30. Still dumps, appearantly the same way.

Here's the program:

	#include <stdio.h>

	char *Date = "$Date: 88/09/09 12:02:35 $";

	main() {
	int y, m, d;
	
	fprintf(stderr, "date is %s\n", Date);
	    sscanf(&Date[7], "%d", &y);
	fprintf(stderr, "y %d\n", y);
	}

If my request to be added to bug-gcc gets honored I should be able to follow
this in the mailing list; I haven't received anything yet. Is there any
bug-gcc traffic these days?

-Bennett
bet@orion.mc.duke.edu (128.109.165.2)

raeburn@ATHENA.MIT.EDU (Ken Raeburn) (10/20/88)

The problem you describe stems from the fact that sscanf (at least in
some stdio implementations) wants to write into one of the strings
passed.  The dpANS C spec says that literal string arguments are not
writable; therefore the string that sscanf tries to write is not in a
writable portion of the program image.

This problem is listed in the GNU CC documentation, in the section
"Incompatibilities of GNU CC".

Try either doing something like

	main () {
	int y, m, d;
	char format[] = "%d";

	/* ... */
	sscanf (&date[7], format, &y);
	/* ... */
	}

(preferable) or compiling with "-fwritable-strings".

-- Ken