Skip to content

Commit 5d79ed6

Browse files
committed
C#: WIP: Fix calls with no target in DB quality query
1 parent 5f41b6d commit 5d79ed6

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

csharp/ql/src/Telemetry/DatabaseQuality.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ module CallTargetStats implements StatsSig {
7777
)
7878
}
7979

80+
private predicate isEventFieldAccess(EventCall c) {
81+
exists(Event e | c.getEvent() = e |
82+
forall(Accessor a | e.getAnAccessor() = a | a.isCompilerGenerated())
83+
)
84+
}
85+
8086
additional predicate isNotOkCall(Call c) {
8187
not exists(c.getTarget()) and
8288
not c instanceof DelegateCall and
@@ -85,7 +91,8 @@ module CallTargetStats implements StatsSig {
8591
not isNoSetterPropertyInitialization(c) and
8692
not isAnonymousObjectMemberDeclaration(c) and
8793
not isInitializedWithCollectionInitializer(c) and
88-
not c.getParent+() instanceof NameOfExpr
94+
not c.getParent+() instanceof NameOfExpr and
95+
not isEventFieldAccess(c)
8996
}
9097

9198
int getNumberOfNotOk() { result = count(Call c | isNotOkCall(c)) }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Quality.cs:25:19:25:26 | access to indexer | Call without target $@. | Quality.cs:25:19:25:26 | access to indexer | access to indexer |
2+
| Quality.cs:28:21:28:27 | access to indexer | Call without target $@. | Quality.cs:28:21:28:27 | access to indexer | access to indexer |
3+
| Quality.cs:31:9:31:21 | access to indexer | Call without target $@. | Quality.cs:31:9:31:21 | access to indexer | access to indexer |
4+
| Quality.cs:46:20:46:26 | object creation of type T | Call without target $@. | Quality.cs:46:20:46:26 | object creation of type T | object creation of type T |

csharp/ql/test/query-tests/Telemetry/DatabaseQuality/NoTarget.expected

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
| Quality.cs:15:24:15:34 | access to property MyProperty3 | Call without target $@. | Quality.cs:15:24:15:34 | access to property MyProperty3 | access to property MyProperty3 |
55
| Quality.cs:15:24:15:46 | access to property MyProperty2 | Call without target $@. | Quality.cs:15:24:15:46 | access to property MyProperty2 | access to property MyProperty2 |
66
| Quality.cs:19:13:19:23 | access to property MyProperty4 | Call without target $@. | Quality.cs:19:13:19:23 | access to property MyProperty4 | access to property MyProperty4 |
7-
| Quality.cs:24:16:24:26 | access to property MyProperty2 | Call without target $@. | Quality.cs:24:16:24:26 | access to property MyProperty2 | access to property MyProperty2 |
7+
| Quality.cs:22:9:22:14 | access to event Event1 | Call without target $@. | Quality.cs:22:9:22:14 | access to event Event1 | access to event Event1 |
8+
| Quality.cs:22:9:22:30 | delegate call | Call without target $@. | Quality.cs:22:9:22:30 | delegate call | delegate call |
9+
| Quality.cs:25:19:25:26 | access to indexer | Call without target $@. | Quality.cs:25:19:25:26 | access to indexer | access to indexer |
10+
| Quality.cs:28:21:28:27 | access to indexer | Call without target $@. | Quality.cs:28:21:28:27 | access to indexer | access to indexer |
11+
| Quality.cs:31:9:31:21 | access to indexer | Call without target $@. | Quality.cs:31:9:31:21 | access to indexer | access to indexer |
12+
| Quality.cs:35:16:35:26 | access to property MyProperty2 | Call without target $@. | Quality.cs:35:16:35:26 | access to property MyProperty2 | access to property MyProperty2 |
13+
| Quality.cs:46:20:46:26 | object creation of type T | Call without target $@. | Quality.cs:46:20:46:26 | object creation of type T | object creation of type T |

csharp/ql/test/query-tests/Telemetry/DatabaseQuality/Quality.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,32 @@ public Test()
1818
{
1919
MyProperty4 = { 1, 2, 3 }
2020
};
21+
22+
Event1.Invoke(this, 5);
23+
24+
var str = "abcd";
25+
var sub = str[..3];
26+
27+
Span<int> sp = null;
28+
var slice = sp[..3];
29+
30+
Span<byte> guidBytes = stackalloc byte[16];
31+
guidBytes[08] = 1;
2132
}
2233

2334
public int MyProperty1 { get; }
2435
public int MyProperty2 { get; } = 42;
2536
public Test MyProperty3 { get; set; }
2637
public List<int> MyProperty4 { get; }
2738
static int MyProperty5 { get; }
39+
40+
public event EventHandler<int> Event1;
41+
42+
class Gen<T> where T : new()
43+
{
44+
public static T Factory()
45+
{
46+
return new T();
47+
}
48+
}
2849
}

0 commit comments

Comments
 (0)