File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
src/codingstandards/cpp/rules/danglingcapturewhenreturninglambdaobject
test/rules/danglingcapturewhenreturninglambdaobject Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 55 */
66
77import cpp
8- import semmle.code.cpp.dataflow.DataFlow
8+ import semmle.code.cpp.dataflow.new. DataFlow
99import codingstandards.cpp.Customizations
1010import codingstandards.cpp.Exclusions
1111
@@ -48,7 +48,14 @@ query predicate problems(
4848 not isExcluded ( returnStmt , getQuery ( ) ) and
4949 lambda .getACapture ( ) = danglingCapture and
5050 (
51- DataFlow:: localExprFlow ( lambda , returnStmt .getExpr ( ) )
51+ returnStmt .getExpr ( ) = lambda
52+ or
53+ exists ( DataFlow:: Node lambdaNode , DataFlow:: Node returnNode |
54+ lambdaNode .asExpr ( ) = lambda and
55+ returnNode .asIndirectExpr ( ) = returnStmt .getExpr ( )
56+ |
57+ DataFlow:: localFlow ( lambdaNode , returnNode )
58+ )
5259 or
5360 // implement a rough heuristic to catch the results of constructors (such as std::function's)
5461 // which take an argument that has a dangling capture and flow to a return statement
Original file line number Diff line number Diff line change 11| test.cpp:6:3:6:12 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:5:12:5:27 | [...](...){...} | object | test.cpp:5:21:5:21 | l1 | l1 |
22| test.cpp:17:5:17:36 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:17:5:17:36 | [...](...){...} | object | test.cpp:17:27:17:27 | (captured this) | this |
33| test.cpp:27:5:27:17 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:26:17:26:42 | [...](...){...} | object | test.cpp:26:33:26:33 | val | val |
4- | test.cpp:27:5:27:17 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:26:18:26:42 | [...](...){...} | object | test.cpp:26:33:26:33 | val | val |
54| test.cpp:33:3:33:33 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:33:3:33:33 | [...](...){...} | object | test.cpp:33:25:33:25 | i | i |
65| test.cpp:37:3:37:33 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:37:3:37:33 | [...](...){...} | object | test.cpp:37:25:37:25 | i | i |
76| test.cpp:46:3:46:45 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:46:11:46:43 | [...](...){...} | object | test.cpp:46:13:46:16 | data | data |
You can’t perform that action at this time.
0 commit comments