earle@SUN.COM (Greg Earle - Sun JPL on-site Software Support - 818-393-1058) (04/05/89)
When I build twm (R3 version) with GNU gcc (1.34 version), it dumps core in twm.c/main() when doing a sscanf() of the Date string into the Version string (line 379 in twm.c). If I compile version.c with `-fwritable-strings' this doesn't happen; can someone provide a hint as to why it does happen (especially since none of the strings defined in version.c are written to; `sscanf' uses the char *Date string to do extractions, but I didn't think it needed to modify a supposed-to-be unwritable string to do so). A patch for version.c to make this problem automagically go away would be nice, too. - Greg Earle Sun Microsystems, Inc. JPL on-site Software Support earle@Sun.COM ...!sun!earle
phil@BRL.MIL (Phil Dykstra) (04/05/89)
The Sun sscanf() routine does an ungetc() that writes in the string. The following patch will allow you to compile twm with gcc without using -fwritable-strings. The fix is due to the folks at CSRI. Your line numbers will vary (I've got other changes in twm.c as well). - Phil *** /tmp/,RCSt1a04232 Wed Apr 5 05:28:45 1989 --- twm.c Mon Mar 27 00:51:47 1989 *************** *** 373,381 **** 0, 0, 5, InitialFont.height + 4, BW, DefaultC.fore, DefaultC.back); /* contruct the version string */ sprintf(Version, "%s", &Revision[1]); Version[strlen(Version) - 1] = '\0'; - sscanf(&Date[7], "%d/%d/%d", &y, &m, &d); sprintf(Version, "%s Date: %d/%d/%d %s", Version, m, d, y, &Date[16]); Version[strlen(Version) - 2] = '\0'; --- 390,399 ---- 0, 0, 5, InitialFont.height + 4, BW, DefaultC.fore, DefaultC.back); /* contruct the version string */ + strcpy(Version, &Date[7]); + sscanf(Version, "%d/%d/%d", &y, &m, &d); sprintf(Version, "%s", &Revision[1]); Version[strlen(Version) - 1] = '\0'; sprintf(Version, "%s Date: %d/%d/%d %s", Version, m, d, y, &Date[16]); Version[strlen(Version) - 2] = '\0';
rlk@THINK.COM (Robert L. Krawitz) (04/05/89)
I recall reading somewhere (the gcc documentation?) that the scanf family of functions is broken; it does try to write its format string. It doesn't "need" to do this, probably; most likely, it does so anyway because someone found that they could get some more speed out of it that way. The other case that's likely to come up is mktemp("stringXXXXXX"). The patch (I don't have the source code, but it's easy enough to figure out) is to declare a variable somewhere that's initialized to the format string of sscanf, and pass it to sscanf. ames >>>>>>>>> | Robert Krawitz <rlk@think.com> 245 First St. bloom-beacon > |think!rlk (postmaster) Cambridge, MA 02142 harvard >>>>>> . Thinking Machines Corp. (617)876-1111