-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C++: Assorted minor doc improvements #16939
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f64743e
C++: Fix mistake in example for cpp/incorrect-allocation-error-handling.
geoffw0 4de43e1
C++: Add the examples to the test.
geoffw0 7abece4
C++: Add a 'good' example for cpp/unsigned-difference-expression-comp…
geoffw0 1343e4c
C++: Add another 'good' example for cpp/unsigned-difference-expressio…
geoffw0 5d89872
C++: Add the examples to the test.
geoffw0 0288499
C++: Rephrase the alert message for cpp/wrong-type-format-argument to…
geoffw0 3c70583
C++: Add close calls to examples for cpp/toctou-race-condition.
geoffw0 d52210d
C++: Improve the example for cpp/return-stack-allocated-memory.
geoffw0 4f0d725
C++: Add a 'good' example as well.
geoffw0 80af5b7
C++: Add a third example for cpp/world-writable-file-creation.
geoffw0 8818f63
C++: Add some practical details to the examples.
geoffw0 7438462
C++: Autoformat.
geoffw0 0344381
Merge remote-tracking branch 'upstream/main' into docsforautofix
geoffw0 bf47574
Merge branch 'main' into docsforautofix
geoffw0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this example isn't caught because the query assumes that any function with no body may throw:
codeql/cpp/ql/src/Security/CWE/CWE-570/IncorrectAllocationErrorHandling.ql
Line 138 in 6359388
As a follow-up to this PR we could add a whitelist of functions we know don't throw to fix this example.
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.
As far as I can tell there is no guarantee that
std::memcpy
doesn't throw in the language standard, but most implementations won't. The one I'm looking appears to get markednothrow
if it's compiled as C++, but not if it's compiled as C, and it appears to get C linkage and notnothrow
in the actual database. It also has a body that just calls a builtin function.So we could perhaps address this by assuming that a C linkage function doesn't throw ... but I don't think it's actually strictly true that a C linkage function can't throw. Or that builtin function don't throw, but again I'm not convinced that's true. Which leaves us with modelling ... we could model functions that don't throw, but again I don't know if it's strictly true that all versions of
memset
don't throw, and it seems a bit heavy handed to model it given thatnothrow
exists.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.
std::memcpy
is from the C standard library, so it cannot throw. But you're right that it's not marked asnoexcept
in the standard.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.
And this is probably the relevant part of the standard:
So since
memcpy
cannot throw in C, and the contents ofcstring
andstring.h
is identical (other than thememchr
stuff), my reading is thatmemcpy
also isn't allowed to throw 🤔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.
You make a good case for modelling. I'll create an issue for this.
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.
Issue created. Thanks for helping me get to the bottom of this!