Red Hat Bugzilla – Bug 190560
while does not return null at end of file
Last modified: 2007-11-30 17:11:31 EST
Description of problem:
Infinite loop while() reading a file, not returning NULL
Version-Release number of selected component (if applicable):
Always, but only on FC5
Steps to Reproduce:
1. See URL with source code.
while() loops forever and doesnt return NULL at end of file.
while loop returns NULL at end of file.
Source code: http://mange.dynalias.org/linux/misc/fc5_bug/test_null_while.c
That testcase is very much broken.
You end up calling fgets with the second argument 1.
fgets reads at most one less than that number of characters from the stream
(i.e. 0) and stores '\0' immediately after the last character stored into the
array (i.e. at line). As at most zero characters are read from the stream,
you never reach EOF and thus it always returns non-NULL.
I guess you meant to pass conf_size+1 to fgets.