Plexus P/40 System III Release 1.2 'C' compiler/library bug

Andy Fyfe wjafyfe at watmath.UUCP
Thu Mar 14 08:34:02 AEST 1985


In article <2142 at wateng.UUCP> ksbszabo at wateng.UUCP (Kevin Szabo) writes:
>In article <395 at aicchi.UUCP> ignatz at aicchi.UUCP (Ihnat) writes:
>>	char buff[64];
>>	setbuf(stdout,buff);
>>
>>Some boring poking with adb resulted in the not surprising
>>fact that the stack and data were crawling down each other's
>>throats; the only surprising thing was that this happened at all
>>on such a small, simple program.  Has anyone else found this?
>
>Setbuf expects the buffer to be BUFSIZ big. STDIO has no
>way of finding out how big your buffer really is.
>Reading the man page for SETBUF should clarify this.
>Peeking at the source ain't bad either.
>
>				Kevin
>-- 
>Kevin Szabo  watmath!wateng!ksbszabo (U of Waterloo VLSI Group, Waterloo Ont.)

Adding any one of the following lines to the end of your program will make
the problem go away.
	exit(0);
	fclose(stdout);
	fflush(stdout);
Once main ends, your buffer goes away (as it's local to main, and allocated
on the stack), and anything in it may be lost.  (It still gets the character
count right!)  If you make buff static, the problem also goes away.

The buffer size will still be a problem, though, if you exceed 64 chars.

--Andy Fyfe		...!{decvax, allegra, ihnp4, et. al}!watmath!wjafyfe
			wjafyfe at waterloo.csnet



More information about the Comp.unix.wizards mailing list