FidoNet Echomail Archive

<<< Previous Index Next >>>

From: Paul Edwards
To: Frank Adam
Date: 1997-02-23 07:48:42
Subject: Re: Borland C bug ?!?

FA> <quote>
FA> The fgets function returns s if successful.  If end-of-file is
FA> encountered and no characters have been read into the array, the
FA> contents of the array remain unchanged and a null pointer is
FA> returned.  If a read error occurs during the operation, the array
FA> contents are indeterminate and a null pointer is returned.  
FA> <end quote>

FA> In other words if fgets returns NULL, s will not contain junk if the 
FA> previous read finished at EOF-1. 
FA> In the avarage text file this will work most of the time as lines will 
FA> be terminated with \n. OTOH s will contain the previous read, so he'll 
FA> end up with two identical lines on the end of the buffer. 
FA> So there IS an *annoying* bug here.

FA> But if the file is corrupt or missing \n on the last line, s will indeed
FA> be junk or unterminated.

No, only if there is some ERROR will that happen, not if it reaches EOF. 
So if there is an error, fgets() will return NULL, and that program would
process junk.  BFN.  Paul.

 * Origin: X (3:711/934.9)