Bug 190560 - while does not return null at end of file
Summary: while does not return null at end of file
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 5
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL: http://mange.dynalias.org/linux/misc/...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-05-03 16:03 UTC by Magnus
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2006-05-03 21:06:10 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Magnus 2006-05-03 16:03:06 UTC
Description of problem:
Infinite loop while() reading a file, not returning NULL

Version-Release number of selected component (if applicable):
glibc-common-2.4-4
glibc-headers-2.4-4
glibc-2.4-4
glibc-kernheaders-3.0-5.2
glibc-devel-2.4-4

How reproducible:
Always, but only on FC5

Steps to Reproduce:
1. See URL with source code.
2.
3.
  
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: http://mange.dynalias.org/linux/misc/fc5_bug/test_null_while.c

Comment 1 Jakub Jelinek 2006-05-03 21:06:10 UTC
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.