Skip to content

Commit be7f7a4

Browse files
committed
C#: Address review comments.
1 parent 3985604 commit be7f7a4

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
category: minorAnalysis
33
---
4-
* C# 14: Added support for user-defined instance increment/decrement operators.
4+
* Improved dataflow support for C# mutation operators.

‎csharp/ql/lib/semmle/code/csharp/Assignable.qll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private newtype TMutationOperationAssignment =
124124
}
125125

126126
/**
127-
* A mutation operation that implicitly assigns the result to its operand. For example, `a++` in
127+
* A mutation operation that implicitly assigns the result to its operand. For example, `a++` on
128128
* line 7 in
129129
*
130130
* ```csharp

‎csharp/ql/lib/semmle/code/csharp/exprs/Dynamic.qll‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class DynamicMethodCall extends DynamicExpr, MethodCall {
9898
*/
9999
class DynamicOperatorCall extends DynamicExpr, OperatorCall { }
100100

101+
private predicate myTest(Call oc) { oc.getARuntimeTarget() instanceof CheckedDecrementOperator }
102+
101103
/**
102104
* A call to a user-defined mutator operator where the operand is a `dynamic`
103105
* expression, for example `d++` on line 20 in

‎csharp/ql/src/Likely Bugs/Dynamic/BadDynamicCall.ql‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ abstract class BadDynamicCall extends DynamicExpr {
5151
)
5252
)
5353
}
54+
55+
private predicate myTest(
56+
Variable v, int i, Expr source, AssignableRead read, SsaDefinition ssaDef,
57+
SsaExplicitWrite ultimateSsaDef, Type t, string tName
58+
) {
59+
read = this.getARelevantVariableAccess(i) and
60+
v = read.getTarget() and
61+
t = source.getType() and
62+
// t.getName() = "MyType" and
63+
tName = t.getFullyQualifiedNameDebug() and
64+
// v.getName() = "d" and
65+
read = ssaDef.getARead() and
66+
ultimateSsaDef = ssaDef.getAnUltimateDefinition() and
67+
ultimateSsaDef.getValue().stripImplicit() = source
68+
}
5469
}
5570

5671
class BadDynamicMethodCall extends BadDynamicCall, DynamicMethodCall {
@@ -70,12 +85,20 @@ class BadDynamicMethodCall extends BadDynamicCall, DynamicMethodCall {
7085
}
7186
}
7287

88+
private predicate myTest(DynamicOperatorCall doc, string targetQlClass, string opName) {
89+
targetQlClass = doc.getARuntimeArgument().getAPrimaryQlClass() and
90+
opName = doc.getLateBoundTargetName() and
91+
opName = "checked --"
92+
}
93+
7394
class BadDynamicOperatorCall extends BadDynamicCall, DynamicOperatorCall {
95+
// BadDynamicOperatorCall() { this.getARuntimeTarget() instanceof CheckedDecrementOperator }
7496
override AssignableRead getARelevantVariableAccess(int i) { result = this.getRuntimeArgument(i) }
7597

7698
override predicate isBad(Variable v, ValueOrRefType pt, Expr pts, string message, string target) {
7799
exists(int i |
78100
pt = this.possibleBadTypeForRelevantSource(v, i, pts) and
101+
pt.getName() = "MyType" and
79102
not pt.containsTypeParameters() and
80103
not exists(Type paramType | paramType = this.getADynamicParameterType(_, i) |
81104
pt.isImplicitlyConvertibleTo(paramType)
@@ -99,7 +122,8 @@ class BadDynamicOperatorCall extends BadDynamicCall, DynamicOperatorCall {
99122

100123
private Type getADynamicParameterType(Operator o, int i) {
101124
o = this.getARuntimeTarget() and
102-
result = o.getParameter(i).getType()
125+
result = o.getParameter(i).getType() and
126+
o.getName() = "checked ++"
103127
}
104128
}
105129

0 commit comments

Comments
 (0)