Skip to content

Commit 0e50a14

Browse files
author
Matthew Gretton-Dann
committed
C++: Improve ReturnStackAllocatedMemory query
Update the ReturnStackAllocatedMmeory query to not give a false positive for thread_local variables.
1 parent a733625 commit 0e50a14

File tree

3 files changed

+2
-2
lines changed

3 files changed

+2
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ predicate hasNontrivialConversion(Expr e) {
4545
from LocalScopeVariable var, VariableAccess va, ReturnStmt r
4646
where
4747
not var.isStatic() and
48+
not var.isThreadLocal() and
4849
not var.getUnspecifiedType() instanceof ReferenceType and
4950
not r.isFromUninstantiatedTemplate(_) and
5051
va = var.getAnAccess() and

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
| test.cpp:92:2:92:12 | return ... | May return stack-allocated memory from $@. | test.cpp:89:10:89:11 | mc | mc |
66
| test.cpp:112:2:112:12 | return ... | May return stack-allocated memory from $@. | test.cpp:112:9:112:11 | arr | arr |
77
| test.cpp:119:2:119:19 | return ... | May return stack-allocated memory from $@. | test.cpp:119:11:119:13 | arr | arr |
8-
| test.cpp:149:3:149:22 | return ... | May return stack-allocated memory from $@. | test.cpp:149:11:149:21 | threadLocal | threadLocal |
98
| test.cpp:171:3:171:24 | return ... | May return stack-allocated memory from $@. | test.cpp:170:35:170:41 | myLocal | myLocal |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ char *testArray5()
146146

147147
int *returnThreadLocal() {
148148
thread_local int threadLocal;
149-
return &threadLocal; // GOOD [FALSE POSITIVE]
149+
return &threadLocal; // GOOD
150150
}
151151

152152
int returnDereferenced() {

0 commit comments

Comments
 (0)