File tree Expand file tree Collapse file tree 3 files changed +7
-13
lines changed
src/Likely Bugs/Memory Management
test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory Expand file tree Collapse file tree 3 files changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -22,16 +22,7 @@ predicate exprMaybeStackAllocated(Expr e) {
2222// is initialized to/assigned a possibly stack allocated expression
2323predicate varMaybeStackAllocated ( LocalVariable lv ) {
2424 not lv .isStatic ( ) and
25- (
26- lv .getType ( ) .getUnderlyingType ( ) instanceof ArrayType
27- or
28- exprMaybeStackAllocated ( lv .getInitializer ( ) .getExpr ( ) )
29- or
30- exists ( AssignExpr a |
31- a .getLValue ( ) .( VariableAccess ) .getTarget ( ) = lv and
32- exprMaybeStackAllocated ( a .getRValue ( ) )
33- )
34- )
25+ not lv .getType ( ) instanceof ReferenceType
3526}
3627
3728// an expression possibly points to the stack if it takes the address of
Original file line number Diff line number Diff line change 1+ | test.cpp:12:2:12:12 | return ... | May return stack-allocated memory. |
2+ | test.cpp:20:2:20:12 | return ... | May return stack-allocated memory. |
3+ | test.cpp:73:2:73:12 | return ... | May return stack-allocated memory. |
14| test.cpp:93:2:93:12 | return ... | May return stack-allocated memory. |
Original file line number Diff line number Diff line change @@ -9,15 +9,15 @@ MyClass *test1()
99{
1010 MyClass mc;
1111
12- return &mc; // BAD [NOT DETECTED]
12+ return &mc; // BAD
1313}
1414
1515MyClass *test2 ()
1616{
1717 MyClass mc;
1818 MyClass *ptr = &mc;
1919
20- return ptr; // BAD [NOT DETECTED]
20+ return ptr; // BAD
2121}
2222
2323MyClass *test3 ()
@@ -70,7 +70,7 @@ MyClass *test10()
7070 ptr = &mc;
7171 }
7272
73- return ptr; // BAD [NOT DETECTED]
73+ return ptr; // BAD
7474}
7575
7676MyClass *test11 (MyClass *param)
You can’t perform that action at this time.
0 commit comments