Fix #958: warn when feof() is used as a while loop condition#8422
Fix #958: warn when feof() is used as a while loop condition#8422francois-berder wants to merge 7 commits into
Conversation
|
How does the check handle |
|
thank you for adding this checker! it's good work. small and simple. just try to make it more precise. |
|
|
I hope some of those CI failures are relatively easy to fix. When you added a checker the checker count increased.. Can you please add a document that explains this checker in cppcheck/man/checkers folder. My long term goal is that all checkers will have a document there. |
|
@danmar I rebased the PR on top of main and fixed the issues you mentioned. I think this PR is now again ready for review. The single CI failure seems to be a timeout unrelated to this PR. |
That CI test is a bit flaky. :-( So if that happens some time again you can assume that it's not related. |
|
@danmar I tried to address your concerns about the check so I added more bailouts. I also rebased the code on a more recent commit. |
|
I also added do-while loops support. |
|
I do not feel that |
I understand your concern, nonetheless I think the combination of This bailout is quite powerful and will clearly create a lot of false negatives.
Do you have in mind a false positive that could be caused by this check? |
|
Alright. We are in the process of making a release so the releasenotes will need to be adjusted. then I think we can merge this. |
|
@danmar I solved the conflict in releasenotes.txt |
… condition 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>
…le loop condition
…s a while loop condition
… used as a while loop condition
…of() is used as a while loop condition
…when feof() is used as a while loop condition
… warn when feof() is used as a while loop condition
|
It seemed that my rebase was wrong so I fixed it. I also updated |



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.