Skip to content

Fix #1473: warn when fclose() is used as a while loop condition#8444

Open
francois-berder wants to merge 1 commit intocppcheck-opensource:mainfrom
francois-berder:pr-1473
Open

Fix #1473: warn when fclose() is used as a while loop condition#8444
francois-berder wants to merge 1 commit intocppcheck-opensource:mainfrom
francois-berder:pr-1473

Conversation

@francois-berder
Copy link
Copy Markdown
Collaborator

Using fclose() as a while loop condition closes the file on every iteration and operates on an already-closed file handle from the second iteration onward.

…oop condition

Using fclose() as a while loop condition closes the file on every
iteration and operates on an already-closed file handle from the
second iteration onward.

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

Comment thread test/testio.cpp
" while (fclose(a)) {}\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3:5]: (error) Used file that is not opened. [useClosedFile]\n", "", errout_str());
ASSERT_EQUALS("[test.cpp:3:12]: (error) Used file that is not opened. [useClosedFile]\n", errout_str());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test that ensures there are no false positives if files are opened in the loop.
I think it's really weird to use a fclose call as a loop condition anyway..

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