C++: Improve ReturnStackAllocatedMemory query

Update the ReturnStackAllocatedMmeory query to not give a false positive
for thread_local variables.
This commit is contained in:
Matthew Gretton-Dann
2019-08-05 18:00:25 +01:00
parent a733625646
commit 0e50a143af
3 changed files with 2 additions and 2 deletions

View File

@@ -45,6 +45,7 @@ predicate hasNontrivialConversion(Expr e) {
from LocalScopeVariable var, VariableAccess va, ReturnStmt r
where
not var.isStatic() and
not var.isThreadLocal() and
not var.getUnspecifiedType() instanceof ReferenceType and
not r.isFromUninstantiatedTemplate(_) and
va = var.getAnAccess() and

View File

@@ -5,5 +5,4 @@
| test.cpp:92:2:92:12 | return ... | May return stack-allocated memory from $@. | test.cpp:89:10:89:11 | mc | mc |
| test.cpp:112:2:112:12 | return ... | May return stack-allocated memory from $@. | test.cpp:112:9:112:11 | arr | arr |
| test.cpp:119:2:119:19 | return ... | May return stack-allocated memory from $@. | test.cpp:119:11:119:13 | arr | arr |
| test.cpp:149:3:149:22 | return ... | May return stack-allocated memory from $@. | test.cpp:149:11:149:21 | threadLocal | threadLocal |
| test.cpp:171:3:171:24 | return ... | May return stack-allocated memory from $@. | test.cpp:170:35:170:41 | myLocal | myLocal |

View File

@@ -146,7 +146,7 @@ char *testArray5()
int *returnThreadLocal() {
thread_local int threadLocal;
return &threadLocal; // GOOD [FALSE POSITIVE]
return &threadLocal; // GOOD
}
int returnDereferenced() {