Skip to content

Commit 14cef6a

Browse files
committed
C++: Fix FPs to cpp/return-stack-allocated-memory
1 parent 8efd870 commit 14cef6a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class ReturnStackAllocatedMemoryConfig extends MustFlowConfiguration {
9292
or
9393
node2.(PointerOffsetInstruction).getLeftOperand() = node1
9494
}
95+
96+
override predicate isBarrier(Instruction n) { n.getResultType() instanceof ErroneousType }
9597
}
9698

9799
from

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// semmle-extractor-options: -std=c++14
1+
// semmle-extractor-options: -std=c++14 --expect_errors
22
class MyClass
33
{
44
public:
@@ -248,4 +248,9 @@ char* test_strdupa(const char* s) {
248248
void* test_strndupa(const char* s, size_t size) {
249249
char* s2 = strndupa(s, size);
250250
return s2; // BAD
251-
}
251+
}
252+
253+
UNKNOWN_TYPE test_error_type() {
254+
UNKNOWN_TYPE x;
255+
return x; // GOOD: Don't report error types
256+
}

0 commit comments

Comments
 (0)