-
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++: Fix FPs to cpp/return-stack-allocated-memory #18309
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* The "Returning stack-allocated memory" query (`cpp/return-stack-allocated-memory`) no longer produces results if there is an extraction error in the type of the function. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// semmle-extractor-options: -std=c++14 | ||
// semmle-extractor-options: -std=c++14 --expect_errors | ||
class MyClass | ||
{ | ||
public: | ||
|
@@ -248,4 +248,9 @@ char* test_strdupa(const char* s) { | |
void* test_strndupa(const char* s, size_t size) { | ||
char* s2 = strndupa(s, size); | ||
return s2; // BAD | ||
} | ||
} | ||
|
||
UNKNOWN_TYPE test_error_type() { | ||
UNKNOWN_TYPE x; | ||
return x; // GOOD: Don't report error types | ||
} | ||
Comment on lines
+253
to
+256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't recall what we did in other cases, but it might be better to have all test cases with parse errors in separate files, because that will mean we catch parse errors that are introduced by accident in "regular" tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not a bad idea to start doing that.
Comment on lines
+253
to
+256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this example is actually fine, because no pointer to |
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.
This is not accurate. It no longer produces a result when there's an
ErroneousType
anywhere on the potential must-flow path (but that is too much detail for a change note). So it might be that the return type of the function is known, but that some critical type within the function is not.Something along the following lines (modifying the example from the QL file):