Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!bbn!ginosko!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.sources.games.bugs Subject: Re: What setbuf() is and why you should use it Keywords: curses fflush setbuf stdio Message-ID: <2245@auspex.auspex.com> Date: 17 Jul 89 17:49:24 GMT References: <283@wet.UUCP> Reply-To: guy@auspex.auspex.com (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 29 >The fix is very simple: put > setbuf(stdout, malloc(BUFSIZ)); > >early in main(), In which case, if you run out of e.g. swap space (or address space, unless you've got tons of it and haven't consumed it all due to some other bug), you may drop core. The fix is very simple; either do register char *bufp; ... if ((bufp = malloc(BUFSIZ)) == NULL) { complain and exit; } setbuf(stdout, bufp); or just do: static char stdoutbuf[BUFSIZ]; ... setbuf(stdout, stdoutbuf); in "main()". (I say "static" because if you return from "main()", it's like exiting, and standard output will be flushed; better safe than sorry.) "malloc" is overkill in this situation....