◐ Shell
reader mode source ↗
Skip to content

fix #381#382

Closed
foryoung365 wants to merge 3 commits into
cppcheck-opensource:masterfrom
foryoung365:master
Closed

fix #381#382
foryoung365 wants to merge 3 commits into
cppcheck-opensource:masterfrom
foryoung365:master

Conversation

@foryoung365

Copy link
Copy Markdown
std::fstream fs(simplePath, std::ios::app);

File existence check using fstream with ios::app is implemented as a workaround because:

  • ifstream::good() incorrectly handles directories on Unix-like systems
  • <sys/stat.h> adds platform-specific dependencies
  • It avoids duplication with CppCheck's 'path' implementation
  • std::filesystem (the proper solution) requires C++17 support

@firewave

Copy link
Copy Markdown
Collaborator

Thanks. Please give me a few days since I might be out sick.

@danmar

danmar commented Dec 5, 2024

Copy link
Copy Markdown
Collaborator

how do we test this? you can easily check if a file exists or not in a unit test but if you need to test various edge cases I guess a pytest working in a tempdir is better.

@firewave

Copy link
Copy Markdown
Collaborator

The issue referenced here was fixed in #443. So I think this can be closed.

And #339 contains improved code for checking for the existence of a file/directory.

I also filed https://trac.cppcheck.net/ticket/14133 about detecting such code with Cppcheck.

@firewave firewave closed this Sep 10, 2025
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.

3 participants