Skip to content

Commit 590cd5a

Browse files
committed
Convert DanglingCaptureWhenReturningLambdaObject to the new dataflow library
Note that this removes - what seems to be - a duplicated test result.
1 parent ab5a471 commit 590cd5a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

cpp/common/src/codingstandards/cpp/rules/danglingcapturewhenreturninglambdaobject/DanglingCaptureWhenReturningLambdaObject.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import cpp
8-
import semmle.code.cpp.dataflow.DataFlow
8+
import semmle.code.cpp.dataflow.new.DataFlow
99
import codingstandards.cpp.Customizations
1010
import 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 numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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 |

0 commit comments

Comments
 (0)