Skip to content

Fix #958: warn when feof() is used as a while loop condition#8422

Open
francois-berder wants to merge 3 commits intodanmar:mainfrom
francois-berder:pr-958
Open

Fix #958: warn when feof() is used as a while loop condition#8422
francois-berder wants to merge 3 commits intodanmar:mainfrom
francois-berder:pr-958

Conversation

@francois-berder
Copy link
Copy Markdown
Contributor

feof() only returns true after a read has already failed, causing the loop body to execute once more after the last successful read. Read errors also go undetected since feof() does not distinguish them from EOF.

feof() only returns true after a read has already failed, causing
the loop body to execute once more after the last successful read.
Read errors also go undetected since feof() does not distinguish
them from EOF.

Signed-off-by: Francois Berder <fberder@outlook.fr>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

@chrchr-github
Copy link
Copy Markdown
Collaborator

How does the check handle do ... while loops? Should we skip those?
There are obviously other ways to check the return value of feof, e.g. using ==. Another extension would be handling of for loops, but maybe that could be added later. @danmar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants