-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ofstreams thow exception on write issues #5255
base: main
Are you sure you want to change the base?
Conversation
6bc3616
to
a07cfa4
Compare
@chrchr-github can you please rerun the failed check? |
Ready for review. A bit bloaty, not sure if all the asserts are needed, maybe I am too defensive. Please note that there are a few TODOs I would like to get reviewed. |
{ | ||
assert(false); | ||
|
||
// TODO report error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how
{ | ||
assert(false); | ||
|
||
// TODO: Report error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how
{ | ||
assert(false); | ||
|
||
// TODO report error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how
In some cases this is by design and would cause existing installations to fail. So this might require a soft deprecation with introducing a warning first in some cases. Also we should add |
@@ -266,7 +281,10 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) | |||
mLatestProgressOutputTime = std::time(nullptr); | |||
|
|||
if (!settings.outputFile.empty()) { | |||
mErrorOutput = new std::ofstream(settings.outputFile); | |||
mErrorOutput = new std::ofstream(); | |||
mErrorOutput->exceptions(std::ios_base::failbit | std::ios_base::badbit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of repeating this pattern across we should introduce a helper function for this.
7b16fdb
to
b6282ef
Compare
b6282ef
to
729f929
Compare
We need to make sure we have tests for all these cases. That also needs to consider the issue addressed in danmar/simplecpp#339 i.e. |
This is related to #5254.
I have observed that if non-existent --cppcheck-build-dir is used, all file writes silently fail.
Should we enable exceptions on std::ofstream(s)?