Skip to content

Commit a354ca3

Browse files
committed
Add null dereference test case with false positive
1 parent 35ee324 commit a354ca3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

csharp/ql/test/query-tests/Nullness/NullMaybe.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ nodes
443443
| NullAlwaysBad.cs:9:30:9:30 | access to parameter s |
444444
| NullMaybeBad.cs:7:27:7:27 | access to parameter o |
445445
| NullMaybeBad.cs:13:17:13:20 | null |
446+
| Params.cs:9:17:9:20 | access to parameter args |
447+
| Params.cs:14:17:14:20 | access to parameter args |
448+
| Params.cs:19:27:19:30 | null |
449+
| Params.cs:20:12:20:15 | null |
446450
| StringConcatenation.cs:14:16:14:23 | SSA def(s) |
447451
| StringConcatenation.cs:15:16:15:16 | access to local variable s |
448452
| StringConcatenation.cs:16:17:16:17 | access to local variable s |
@@ -831,6 +835,8 @@ edges
831835
| GuardedString.cs:34:26:34:26 | 0 | GuardedString.cs:35:31:35:31 | access to local variable s |
832836
| NullAlwaysBad.cs:7:29:7:29 | SSA param(s) | NullAlwaysBad.cs:9:30:9:30 | access to parameter s |
833837
| NullMaybeBad.cs:13:17:13:20 | null | NullMaybeBad.cs:7:27:7:27 | access to parameter o |
838+
| Params.cs:19:27:19:30 | null | Params.cs:9:17:9:20 | access to parameter args |
839+
| Params.cs:20:12:20:15 | null | Params.cs:14:17:14:20 | access to parameter args |
834840
| StringConcatenation.cs:14:16:14:23 | SSA def(s) | StringConcatenation.cs:15:16:15:16 | access to local variable s |
835841
| StringConcatenation.cs:15:16:15:16 | access to local variable s | StringConcatenation.cs:16:17:16:17 | access to local variable s |
836842
#select
@@ -918,4 +924,6 @@ edges
918924
| E.cs:417:34:417:34 | access to parameter i | E.cs:417:24:417:40 | SSA capture def(i) | E.cs:417:34:417:34 | access to parameter i | Variable $@ may be null at this access because it has a nullable type. | E.cs:415:27:415:27 | i | i | E.cs:415:27:415:27 | i | this |
919925
| GuardedString.cs:35:31:35:31 | access to local variable s | GuardedString.cs:7:16:7:32 | SSA def(s) | GuardedString.cs:35:31:35:31 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | GuardedString.cs:7:16:7:16 | s | s | GuardedString.cs:7:16:7:32 | String s = ... | this |
920926
| NullMaybeBad.cs:7:27:7:27 | access to parameter o | NullMaybeBad.cs:13:17:13:20 | null | NullMaybeBad.cs:7:27:7:27 | access to parameter o | Variable $@ may be null at this access because of $@ null argument. | NullMaybeBad.cs:5:25:5:25 | o | o | NullMaybeBad.cs:13:17:13:20 | null | this |
927+
| Params.cs:9:17:9:20 | access to parameter args | Params.cs:19:27:19:30 | null | Params.cs:9:17:9:20 | access to parameter args | Variable $@ may be null at this access because of $@ null argument. | Params.cs:7:36:7:39 | args | args | Params.cs:19:27:19:30 | null | this |
928+
| Params.cs:14:17:14:20 | access to parameter args | Params.cs:20:12:20:15 | null | Params.cs:14:17:14:20 | access to parameter args | Variable $@ may be null at this access because of $@ null argument. | Params.cs:12:36:12:39 | args | args | Params.cs:20:12:20:15 | null | this |
921929
| StringConcatenation.cs:16:17:16:17 | access to local variable s | StringConcatenation.cs:14:16:14:23 | SSA def(s) | StringConcatenation.cs:16:17:16:17 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | StringConcatenation.cs:14:16:14:16 | s | s | StringConcatenation.cs:14:16:14:23 | String s = ... | this |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
public class Params
6+
{
7+
public void M1(params string[] args)
8+
{
9+
var l = args.Length; // FALSE POSITIVE
10+
}
11+
12+
public void M2(params string[] args)
13+
{
14+
var l = args.Length; // Good
15+
}
16+
17+
public void M()
18+
{
19+
M1("a", "b", "c", null);
20+
M2(null);
21+
}
22+
}

0 commit comments

Comments
 (0)