bug in stdio (setbuf) ?

crl at CSvax crl at CSvax
Sat Sep 10 02:18:41 AEST 1983


I think I have discovered a bug in the way stdio handles its buffers
when you've used setbuf().  We run 2.8 BSD, but I bet it's present
elsewhere.  It seems that iop->_base is not set to NULL by fclose
if you've used a setbuf() to assign your own buffer.  The specific
code is:
	if (iop->_flag & _IOMYBUF)
		free(iop->_base);
	if (iop->_flag & (_IOMYBUF|_IONBF))
		iop->_base = NULL;
in fclose().  Thus, if _base was pointing to your stack, you'll in for
problems the next time you fopen() since this does not zero it either.
I can't think of a good reason why _base should not be zeroed on an
fclose().  Comments?

Charles LaBrec
UUCP:		pur-ee!Physics:crl, purdue!Physics:crl
INTERNET:	crl @ pur-phy.UUCP



More information about the Net.bugs mailing list