Skip to content

Commit ec68e91

Browse files
committed
C#: Re-factor LambdaDataFlow to use the new API.
1 parent 49d3356 commit ec68e91

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

csharp/ql/src/Language Abuse/ForeachCapture.ql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ predicate inForeachStmtBody(ForeachStmt loop, Element e) {
3737
)
3838
}
3939

40-
class LambdaDataFlowConfiguration extends DataFlow::Configuration {
41-
LambdaDataFlowConfiguration() { this = "LambdaDataFlowConfiguration" }
40+
module LambdaDataFlowConfig implements DataFlow::ConfigSig {
41+
predicate isSource(DataFlow::Node source) { lambdaCapturesLoopVariable(source.asExpr(), _, _) }
4242

43-
override predicate isSource(DataFlow::Node source) {
44-
lambdaCapturesLoopVariable(source.asExpr(), _, _)
45-
}
43+
predicate isSink(DataFlow::Node sink) { exists(getAssignmentTarget(sink.asExpr())) }
44+
}
4645

47-
override predicate isSink(DataFlow::Node sink) { exists(getAssignmentTarget(sink.asExpr())) }
46+
module LambdaDataFlow {
47+
private import DataFlow::Global<LambdaDataFlowConfig>
4848

4949
predicate capturesLoopVarAndIsStoredIn(
5050
AnonymousFunctionExpr lambda, Variable loopVar, Element storage
5151
) {
52-
exists(DataFlow::Node sink | this.hasFlow(DataFlow::exprNode(lambda), sink) |
52+
exists(DataFlow::Node sink | flow(DataFlow::exprNode(lambda), sink) |
5353
storage = getAssignmentTarget(sink.asExpr())
5454
) and
5555
exists(ForeachStmt loop | lambdaCapturesLoopVariable(lambda, loop, loopVar) |
@@ -109,7 +109,7 @@ predicate declaredInsideLoop(ForeachStmt loop, LocalVariable v) {
109109
)
110110
}
111111

112-
from LambdaDataFlowConfiguration c, AnonymousFunctionExpr lambda, Variable loopVar, Element storage
113-
where c.capturesLoopVarAndIsStoredIn(lambda, loopVar, storage)
112+
from AnonymousFunctionExpr lambda, Variable loopVar, Element storage
113+
where LambdaDataFlow::capturesLoopVarAndIsStoredIn(lambda, loopVar, storage)
114114
select lambda, "Function which may be stored in $@ captures variable $@.", storage,
115115
storage.toString(), loopVar, loopVar.getName()

0 commit comments

Comments
 (0)