Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
C++: Fix FPs to cpp/return-stack-allocated-memory
  • Loading branch information
calumgrant committed Dec 17, 2024
commit 14cef6a20722e36ca0cdcdfe008add473183efe8
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class ReturnStackAllocatedMemoryConfig extends MustFlowConfiguration {
or
node2.(PointerOffsetInstruction).getLeftOperand() = node1
}

override predicate isBarrier(Instruction n) { n.getResultType() instanceof ErroneousType }
}

from
Expand Down
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:
Expand Down Expand Up @@ -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
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not a bad idea to start doing that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this example is actually fine, because no pointer to x is being returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a regression (embarrassing result), where this was actually flagged as an alert. But the commit history does not contain the failing test being fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Loading