[comp.sys.mac.programmer] New scanf bug

gary@sun.mcs.clarkson.edu (Gary Levin) (11/01/89)

A new scanf bug has appeared.  If you read a string using %*s, the
unassigned string is stored in a random memory location (pointer 0).

This accounted for my earlier problem of an alert message being
changed.  Apparently, using separate strings put the text in memory
location 0.  Under the debugger, something else must be there.

Correction to ``scanf.c'' in ANSI shown below; just add the line above
the ***.  Please report any other errors found.  It would be
appreciated if the Symantec folks would periodically post bug reports
from other sources to this list.


 string:
    if (!F.haveWidth)
        F.fieldWidth = INT_MAX;
    if (!F.suppress)
	s = va_arg(arg, char *);
    for (; c != EOF; c = getc(fp), ++nread) {
	--F.fieldWidth;
	if (!testbit(c))
	    break;
	F.valid = TRUE;
	if (!F.suppress) *s++ = c;
	****************  only assign if not suppressed.
	if (F.fieldWidth == 0)
	    goto endstring;
    }
    ungetc(c, fp), --nread;
 endstring:
    if (!F.valid)
	goto done;
    if (!F.suppress) {
	*s = 0;
	++nassigned;
    }
    ++nconverted;
    continue;
--
Gary Levin/Dept of Math & CS/Clarkson Univ/Potsdam, NY 13676/(315) 268-2384
BitNet: gary@clutx   Internet: gary@clutx.clarkson.edu

6600pete@hub.UUCP (11/01/89)

From article <GARY.89Oct31132216@sun.clarkson.edu>,
by gary@sun.mcs.clarkson.edu (Gary Levin):

> A new scanf bug has appeared.

I got a recent fix for a THINK C 4 scanf bug off of... well, one of
those OTHER online services recently. I don't know if it fixes the
same bug, but it's an official THINK patch, so people might want to
want for comp.binaries.mac to post it.
Pete Gontier   : pete@cavevax.ucsb.edu; outgoing .UUCP addresses bounce
Editor, Macker : Online Macintosh Programming Journal; mail for subscription
Hire this kid  : Mac, DOS, C, Pascal, asm, excellent communication skills
Underground    : Internet BBS via rlogin 128.11.41.100 -l bbs