Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watmath.UUCP Path: utzoo!watmath!wjafyfe From: wjafyfe@watmath.UUCP (Andy Fyfe) Newsgroups: net.unix-wizards Subject: Re: Plexus P/40 System III Release 1.2 'C' compiler/library bug Message-ID: <11929@watmath.UUCP> Date: Wed, 13-Mar-85 17:34:02 EST Article-I.D.: watmath.11929 Posted: Wed Mar 13 17:34:02 1985 Date-Received: Thu, 14-Mar-85 03:20:15 EST References: <395@aicchi.UUCP> <2142@wateng.UUCP> Reply-To: wjafyfe@watmath.UUCP (Andy Fyfe) Distribution: net Organization: U of Waterloo, Ontario Lines: 32 Summary: In article <2142@wateng.UUCP> ksbszabo@wateng.UUCP (Kevin Szabo) writes: >In article <395@aicchi.UUCP> ignatz@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@waterloo.csnet