This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 190560 - while does not return null at end of file
while does not return null at end of file
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2006-05-03 12:03 EDT by Magnus
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-05-03 17:06:10 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Magnus 2006-05-03 12:03:06 EDT
Description of problem:
Infinite loop while() reading a file, not returning NULL

Version-Release number of selected component (if applicable):

How reproducible:
Always, but only on FC5

Steps to Reproduce:
1. See URL with source code.
Actual results:
while() loops forever and doesnt return NULL at end of file.

Expected results:
while loop returns NULL at end of file.

Additional info:
Source code:
Comment 1 Jakub Jelinek 2006-05-03 17:06:10 EDT
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[0]).  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.

Note You need to log in before you can comment on or make changes to this bug.