[comp.sys.mac.programmer] Bug in THINK C????

rhutchin@Bonnie.ICS.UCI.EDU (02/19/91)

Well, more like "Bug in THINK C 4.02 update..."

Here's something that is compiled into "error-free" object code in THINK C 4.0:

	NumToString((long) BuffCopy, tempStr);

where:
	char  *BuffCopy
	char  *tempStr;  /* sorry, forget the ";" above */

This works great in 4.0, but in the 4.02 update, it doesn't; it generates
a bus error, that I catch in MacsBug...

Sorry I can't give more information; I'm kindof a novice C programmer and
MacsBug user.

Anyone else had this problem.  Does Symantec know about it?

Richard B. Hutchings
Dept of Info and Comp Sci
UC Irvine

siegel@endor.uucp (Rich Siegel) (02/19/91)

In article <9102181103.aa10735@Bonnie.ics.uci.edu> rhutchin@Bonnie.ICS.UCI.EDU writes:
>Well, more like "Bug in THINK C 4.02 update..."
>
>Here's something that is compiled into "error-free" object code in THINK C 4.0:
>
>	NumToString((long) BuffCopy, tempStr);
>
>where:
>	char  *BuffCopy
>	char  *tempStr;  /* sorry, forget the ";" above */

	Unless "tempStr" is initialized to point at real storage, the
NumToString call will write the result out into random memory, which can 
cause all sorts of unpredictable behavior, bus errors being among the
symptoms. Try:

	char *buffCopy;
	Str255 tempStr;
	NumToString(buffCopy, tempStr);

R.



 Rich Siegel	Symantec Languages Group  Internet: siegel@endor.harvard.edu

"I was just trying to be subtle. That's my job, isn't it?"

oster@well.sf.ca.us (David Phillip Oster) (02/20/91)

In article <9102181103.aa10735@Bonnie.ics.uci.edu> rhutchin@Bonnie.ICS.UCI.EDU writes:
>Here's something that is compiled into "error-free" object code in THINK C 4.0:
>	NumToString((long) BuffCopy, tempStr);

>where:
>	char  *BuffCopy;
>	char  *tempStr;

you know that the result has to go into a place, i.e.,:

	char *buffCopy;	/* local variables initially contain garbage */
	char *tempStr;
	char strBuf[100];

	tempStr = strBuf;	/* make tempStr point at a real place */
	NumToString((long) buffCopy, tempStr);
-- 
-- David Phillip Oster - At least the government doesn't make death worse.
-- oster@well.sf.ca.us = {backbone}!well!oster