Text File

Aucbvax.2483 fa.unix-wizards utzoo!decvax!ucbvax!dsp.dove@MIT-SPEECH@MIT-AI Thu Jul 30 16:52:15 1981 stdio bug From: web <DSP.DOVE@MIT-SPEECH@MIT-AI> There is a bug in the Bell and Berkeley stdio package. If one types a line of code into the stdin buffer (_sibuf), then closes stdin, fopens a disk file, writes a char and exits, the typed in line (which had not been read) will be in the disk file. This problem occurs because the fclose operation only deallocates buffers it itself has allocated (of which _sibuf is not one) and if it doesn't free a buffer it neglects to reset iob->_ptr=iob->_base when in sets iob->_cnt=0 . The next time flsbuf is called on that buffer, the difference between _ptr and _base is written out. A simple fix is to add the assignment:

iob->_ptr=iob->_base;

after

iob->_cnt=0;

in fclose().

However, this seems to be the result of poor planning of the whole package. For example:

one cannot setbuf with a larger buf than BUFSIZ.

one cannot read and write the same buffered file.

using buffered i/o on a raw file is risky at best.

once a setbuf is done, fclosing that file then fopenning another might cause accidental use of the original setbuf buffer (which could possibly be from an invalid stack frame!).

Are there alternatives to using this package which implement the same calls? -------

----------------------------------------------------------------- gopher://quux.org/ conversion by John Goerzen <jgoerzen@complete.org> of http://communication.ucsd.edu/A-News/

This Usenet Oldnews Archive article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.

2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996 Bruce Jones, Henry Spencer, David Wiseman.