🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #143

gcc 1.35 - sscanf bug?

#143
From: Don Becker
Date: Wed, 05 Jul 1989 17:09
30 lines
1672 bytes
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
Technical Details
Message-ID: <8907051710.AA00837@trantor.harris-atd.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!TRANTOR.HARRIS-ATD.COM!becker
References: <18251@usc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!TRANTOR.HARRIS-ATD.COM!becker
From: becker@TRANTOR.HARRIS-ATD.COM (Don Becker)
Newsgroups: gnu.gcc.bug
Subject: gcc 1.35 - sscanf bug?
Message-ID: <8907051710.AA00837@trantor.harris-atd.com>
Date: 5 Jul 89 17:09:30 GMT
References: <18251@usc.edu>
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 30