Skip to content

Commit 53d4d72

Browse files
committed
C#: Simplify SummarizedCallableDefaultClearsContent
1 parent dd138b0 commit 53d4d72

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/FlowSummary.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ module SummaryComponentStack {
7979
class SummarizedCallable = Impl::Public::SummarizedCallable;
8080

8181
private class SummarizedCallableDefaultClearsContent extends Impl::Public::SummarizedCallable {
82-
SummarizedCallable c;
83-
84-
SummarizedCallableDefaultClearsContent() { this = c }
82+
SummarizedCallableDefaultClearsContent() {
83+
this instanceof Impl::Public::SummarizedCallable or none()
84+
}
8585

8686
// By default, we assume that all stores into arguments are definite
8787
override predicate clearsContent(int i, DataFlow::Content content) {
8888
exists(SummaryComponentStack output |
89-
c.propagatesFlow(_, output, _) and
89+
this.propagatesFlow(_, output, _) and
9090
output.drop(_) =
9191
SummaryComponentStack::push(SummaryComponent::content(content),
9292
SummaryComponentStack::argument(i)) and

csharp/ql/test/library-tests/dataflow/external-models/steps.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ summarySetterStep
2121
| Steps.cs:30:34:30:34 | 0 | Steps.cs:30:13:30:16 | [post] this access | Steps.cs:57:13:57:17 | field Field |
2222
| Steps.cs:34:37:34:37 | 0 | Steps.cs:34:13:34:16 | [post] this access | Steps.cs:63:13:63:20 | property Property |
2323
| Steps.cs:38:36:38:36 | 0 | Steps.cs:38:13:38:16 | [post] this access | file://:0:0:0:0 | element |
24+
clearsContent
25+
| Steps.cs:61:14:61:28 | StepFieldSetter | Steps.cs:57:13:57:17 | field Field | -1 |
26+
| Steps.cs:67:14:67:31 | StepPropertySetter | Steps.cs:63:13:63:20 | property Property | -1 |

csharp/ql/test/library-tests/dataflow/external-models/steps.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import csharp
22
import DataFlow
33
import semmle.code.csharp.dataflow.ExternalFlow
4+
import semmle.code.csharp.dataflow.FlowSummary
45
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
56
import CsvValidation
67

@@ -40,3 +41,8 @@ query predicate summaryGetterStep(DataFlow::Node arg, DataFlow::Node out, Conten
4041
query predicate summarySetterStep(DataFlow::Node arg, DataFlow::Node out, Content c) {
4142
FlowSummaryImpl::Private::Steps::summarySetterStep(arg, c, out)
4243
}
44+
45+
query predicate clearsContent(SummarizedCallable c, DataFlow::Content k, int i) {
46+
c.clearsContent(i, k) and
47+
c.fromSource()
48+
}

0 commit comments

Comments
 (0)