Skip to content

Commit f5808d1

Browse files
committed
C#: Add compound assignment operator data flow example.
1 parent 39b044b commit f5808d1

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

csharp/ql/test/library-tests/dataflow/operators/Operator.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,39 @@ public void M6()
8484
var y = Source<C>(12);
8585
M6Aux(x, y);
8686
}
87-
}
87+
}
88+
89+
public class CompoundAssignmentOperators
90+
{
91+
static void Sink(object o) { }
92+
static T Source<T>(object source) => throw null;
93+
94+
public class C
95+
{
96+
public object Field { get; private set; }
97+
98+
public C()
99+
{
100+
Field = new object();
101+
}
102+
103+
public C(object o)
104+
{
105+
Field = o;
106+
}
107+
108+
public void operator +=(C x)
109+
{
110+
Field = x.Field;
111+
}
112+
}
113+
114+
public void M1()
115+
{
116+
var tainted = Source<object>(1);
117+
var x = new C();
118+
var y = new C(tainted);
119+
x += y;
120+
Sink(x.Field); // $ hasValueFlow=1
121+
}
122+
}

csharp/ql/test/library-tests/dataflow/operators/operatorFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ subpaths
219219
| Operator.cs:77:29:77:29 | access to parameter y : C | Operator.cs:22:51:22:51 | y : C | Operator.cs:22:57:22:57 | access to parameter y : C | Operator.cs:77:25:77:29 | call to operator checked / : C |
220220
| Operator.cs:77:29:77:29 | access to parameter y : C | Operator.cs:22:51:22:51 | y : C | Operator.cs:22:57:22:57 | access to parameter y : C | Operator.cs:77:25:77:29 | call to operator checked / : C |
221221
testFailures
222+
| Operator.cs:120:24:120:42 | // ... | Missing result: hasValueFlow=1 |
222223
#select
223224
| Operator.cs:30:14:30:14 | access to local variable z | Operator.cs:27:17:27:28 | call to method Source<C> : C | Operator.cs:30:14:30:14 | access to local variable z | $@ | Operator.cs:27:17:27:28 | call to method Source<C> : C | call to method Source<C> : C |
224225
| Operator.cs:30:14:30:14 | access to local variable z | Operator.cs:27:17:27:28 | call to method Source<C> : C | Operator.cs:30:14:30:14 | access to local variable z | $@ | Operator.cs:27:17:27:28 | call to method Source<C> : C | call to method Source<C> : C |

0 commit comments

Comments
 (0)