[gnu.gcc.bug] gcc 1.35 - sscanf bug?

becker@TRANTOR.HARRIS-ATD.COM (Don Becker) (07/06/89)

I'm certain you have already recieved many answers about you "gcc"
problem, but just in case you haven't:

Your core dump is a result of GCC putting the constant character array
'Date' in the read-only part of the executable.  Changing the declaration
and initialization from:
	char *Date = "88/10/18"; /* An char* initialized with a constant string*/
to
	char Date[] = "88/10/18";	/* An initialized array */
will fix your problem.

The core file is really a result of the way the Sun C library implements
sscanf().  It puts the pointer to the string in a <stdio.h> FILE
structure, and then uses _doscan just as it would if you called
fscanf().  _doscan thinks it is working with a real file, and it tries
to ungetc() characters from the string, attempting to write a
read-only page in the process.  This is documented in gcc.texinfo.

File: gcc.info  Node: Incompatibilities

   * GNU CC normally makes string constants read-only...
...
     Another consequence is that `sscanf' does not work on some
     systems when passed a string constant as its format control string.
     This is because `sscanf' incorrectly tries to write into the
     string constant.  Likewise `fscanf' and `scanf'.


				Don Becker