C#: Update guards tests.

This commit is contained in:
Calum Grant
2019-12-12 17:04:14 +00:00
committed by Calum Grant
parent ecb22f1379
commit 2eb29224e8
10 changed files with 81 additions and 78 deletions

View File

@@ -1 +1,2 @@
// semmle-extractor-options: /langversion:8.0
#nullable enable

View File

@@ -73,7 +73,7 @@ abstractValue
| empty | Collections.cs:87:30:87:31 | { ..., ... } |
| empty | Collections.cs:88:22:88:23 | { ..., ... } |
| false | Guards.cs:178:16:178:20 | false |
| false | Guards.cs:181:52:181:56 | false |
| false | Guards.cs:181:53:181:57 | false |
| false | Guards.cs:217:18:217:22 | false |
| false | Guards.cs:228:18:228:22 | false |
| false | Guards.cs:295:18:295:22 | false |
@@ -153,7 +153,7 @@ abstractValue
| non-null | Guards.cs:92:30:92:30 | (...) ... |
| non-null | Guards.cs:96:18:96:19 | "" |
| non-null | Guards.cs:105:19:105:33 | object creation of type Exception |
| non-null | Guards.cs:183:37:183:48 | this access |
| non-null | Guards.cs:183:38:183:49 | this access |
| non-null | Guards.cs:189:14:189:25 | this access |
| non-null | Guards.cs:191:14:191:25 | this access |
| non-null | Guards.cs:193:14:193:25 | this access |
@@ -206,9 +206,9 @@ abstractValue
| null | Guards.cs:115:52:115:55 | null |
| null | Guards.cs:117:9:117:25 | ... = ... |
| null | Guards.cs:117:22:117:25 | null |
| null | Guards.cs:172:38:172:41 | null |
| null | Guards.cs:181:38:181:41 | null |
| null | Guards.cs:185:42:185:45 | null |
| null | Guards.cs:172:39:172:42 | null |
| null | Guards.cs:181:39:181:42 | null |
| null | Guards.cs:185:43:185:46 | null |
| null | Guards.cs:203:18:203:21 | null |
| null | Splitting.cs:12:22:12:25 | null |
| null | Splitting.cs:22:22:22:25 | null |
@@ -221,12 +221,12 @@ abstractValue
| null | Splitting.cs:97:31:97:34 | null |
| null | Splitting.cs:105:27:105:30 | null |
| null | Splitting.cs:116:27:116:30 | null |
| null | Splitting.cs:125:20:125:23 | null |
| null | Splitting.cs:125:21:125:24 | null |
| null | Splitting.cs:128:22:128:25 | null |
| true | Guards.cs:177:20:177:23 | true |
| true | Guards.cs:181:45:181:48 | true |
| true | Guards.cs:185:49:185:52 | true |
| true | Guards.cs:185:56:185:59 | true |
| true | Guards.cs:181:46:181:49 | true |
| true | Guards.cs:185:50:185:53 | true |
| true | Guards.cs:185:57:185:60 | true |
| true | Guards.cs:215:18:215:21 | true |
| true | Guards.cs:220:18:220:21 | true |
| true | Guards.cs:230:18:230:21 | true |

View File

@@ -73,8 +73,8 @@
| Guards.cs:198:31:198:31 | access to parameter s | Guards.cs:197:14:197:29 | call to method NullTestWrong | Guards.cs:197:28:197:28 | access to parameter s | false |
| Guards.cs:205:13:205:13 | access to parameter o | Guards.cs:203:13:203:21 | ... != ... | Guards.cs:203:13:203:13 | access to parameter o | true |
| Guards.cs:208:17:208:17 | access to parameter o | Guards.cs:203:13:203:21 | ... != ... | Guards.cs:203:13:203:13 | access to parameter o | true |
| Guards.cs:269:11:269:12 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true |
| Guards.cs:271:11:271:12 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true |
| Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true |
| Guards.cs:271:13:271:14 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true |
| Splitting.cs:13:17:13:17 | access to parameter o | Splitting.cs:12:17:12:25 | ... != ... | Splitting.cs:12:17:12:17 | access to parameter o | true |
| Splitting.cs:23:24:23:24 | access to parameter o | Splitting.cs:22:17:22:25 | ... != ... | Splitting.cs:22:17:22:17 | access to parameter o | true |
| Splitting.cs:25:13:25:13 | access to parameter o | Splitting.cs:22:17:22:25 | ... != ... | Splitting.cs:22:17:22:17 | access to parameter o | false |

View File

@@ -1 +1,2 @@
// semmle-extractor-options: --cil /langversion:8.0
#nullable enable

View File

@@ -171,10 +171,10 @@
| Guards.cs:205:13:205:13 | access to parameter o | Guards.cs:203:13:203:21 | ... != ... | Guards.cs:203:13:203:13 | access to parameter o | true |
| Guards.cs:208:17:208:17 | access to parameter o | Guards.cs:203:13:203:13 | access to parameter o | Guards.cs:203:13:203:13 | access to parameter o | non-null |
| Guards.cs:208:17:208:17 | access to parameter o | Guards.cs:203:13:203:21 | ... != ... | Guards.cs:203:13:203:13 | access to parameter o | true |
| Guards.cs:269:11:269:12 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:269:11:269:12 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true |
| Guards.cs:269:11:269:12 | access to parameter o1 | Guards.cs:268:16:268:25 | call to method GetType | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:271:11:271:12 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true |
| Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true |
| Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:16:268:25 | call to method GetType | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:271:13:271:14 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true |
| Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | match access to type Action<Object> |
| Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | non-null |
| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | match "" |

View File

@@ -171,10 +171,10 @@
| Guards.cs:205:13:205:13 | access to parameter o | Guards.cs:203:13:203:21 | ... != ... | Guards.cs:203:13:203:13 | access to parameter o | true |
| Guards.cs:208:17:208:17 | access to parameter o | Guards.cs:203:13:203:13 | access to parameter o | Guards.cs:203:13:203:13 | access to parameter o | non-null |
| Guards.cs:208:17:208:17 | access to parameter o | Guards.cs:203:13:203:21 | ... != ... | Guards.cs:203:13:203:13 | access to parameter o | true |
| Guards.cs:269:11:269:12 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:269:11:269:12 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true |
| Guards.cs:269:11:269:12 | access to parameter o1 | Guards.cs:268:16:268:25 | call to method GetType | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:271:11:271:12 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true |
| Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true |
| Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:16:268:25 | call to method GetType | Guards.cs:268:13:268:14 | access to parameter o1 | non-null |
| Guards.cs:271:13:271:14 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true |
| Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | match access to type Action<Object> |
| Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | non-null |
| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | match "" |

View File

@@ -2,10 +2,10 @@ using System;
public class Guards
{
public string Field;
public Guards Property { get; set; }
public string? Field;
public Guards? Property { get; set; }
void M1(string s)
void M1(string? s)
{
if (!!(s == null))
return;
@@ -19,7 +19,7 @@ public class Guards
}
}
void M2(string s)
void M2(string? s)
{
if (s != null)
{
@@ -27,7 +27,7 @@ public class Guards
}
}
void M3(string x, string y)
void M3(string? x, string? y)
{
if (!string.IsNullOrEmpty(x) & !(y == null))
Console.WriteLine(x + y); // null guarded
@@ -63,7 +63,7 @@ public class Guards
Console.WriteLine(g.Property.Field); // not null guarded
}
void M6(string s)
void M6(string? s)
{
while (s != null)
{
@@ -73,7 +73,7 @@ public class Guards
}
}
void M7(string s)
void M7(string? s)
{
if (s?.Length == 0)
Console.WriteLine(s); // null guarded
@@ -119,34 +119,34 @@ public class Guards
Console.WriteLine(g.Property.Field); // not null guarded
}
void M10(string s1, string s2)
void M10(string? s1, string? s2)
{
var b1 = s1.Equals(s2); // not null guarded
var b2 = s1?.Equals(s1); // null guarded
}
int M11(string s)
int M11(string? s)
{
if (s is null)
return s.Length; // not null guarded
return s.Length; // null guarded
}
int M12(string s)
int M12(string? s)
{
if (s is string _)
return s.Length; // null guarded
return s.Length; // not null guarded
}
string M13(object o)
string M13(object? o)
{
if (o is string s)
return s; // not null (but not a guard)
return o.ToString(); // not null guarded
}
string M14(object o)
string M14(object? o)
{
switch (o)
{
@@ -163,28 +163,28 @@ public class Guards
}
}
void M15(string x)
void M15(string? x)
{
if (!string.IsNullOrWhiteSpace(x))
Console.WriteLine(x); // null guarded
}
bool NullTest1(object o) => o == null;
bool NullTest1(object? o) => o == null;
bool NullTest2(object o)
bool NullTest2(object? o)
{
if (o is null)
return true;
return false;
}
bool NullTest3(object o) => o == null ? true : false;
bool NullTest3(object? o) => o == null ? true : false;
bool NotNullTest4(object o) => !NullTest3(o);
bool NotNullTest4(object? o) => !NullTest3(o);
bool NullTestWrong(object o) => o == null ? true : true;
bool NullTestWrong(object? o) => o == null ? true : true;
void M16(string s)
void M16(string? s)
{
if (!NullTest1(s))
Console.WriteLine(s); // null guarded
@@ -198,7 +198,7 @@ public class Guards
Console.WriteLine(s); // not null guarded
}
void M17(object o, string[] args)
void M17(object? o, string[] args)
{
if (o != null)
{
@@ -217,9 +217,9 @@ public class Guards
b2 = false;
switch (b2)
{
case true :
case true:
return;
return;
return;
}
}
@@ -230,9 +230,9 @@ public class Guards
b2 = true;
switch (b2)
{
case true :
case true:
return;
return;
return;
}
}
@@ -243,9 +243,9 @@ public class Guards
i = 1;
switch (i)
{
case 1 :
case 1:
return;
return;
return;
}
}
@@ -257,21 +257,21 @@ public class Guards
e = E.B;
switch (e)
{
case E.B :
case E.B:
return;
return;
return;
}
}
void M22(object o1, object o2)
void M22(object? o1, object? o2)
{
if (o1?.GetType() == o2.GetType())
o1.ToString(); // null guarded
o1.ToString(); // null guarded
if (o1?.GetType() == o2?.GetType())
o1.ToString(); // not null guarded
o1.ToString(); // not null guarded
}
string M23(object o)
string M23(object? o)
{
return o switch
{
@@ -336,3 +336,4 @@ public class Guards
};
}
}

View File

@@ -334,22 +334,22 @@
| Guards.cs:168:13:168:41 | !... | false | Guards.cs:168:14:168:41 | call to method IsNullOrWhiteSpace | true |
| Guards.cs:168:13:168:41 | !... | true | Guards.cs:168:14:168:41 | call to method IsNullOrWhiteSpace | false |
| Guards.cs:168:14:168:41 | call to method IsNullOrWhiteSpace | false | Guards.cs:168:40:168:40 | access to parameter x | non-null |
| Guards.cs:172:33:172:41 | ... == ... | false | Guards.cs:172:33:172:33 | access to parameter o | non-null |
| Guards.cs:172:33:172:41 | ... == ... | true | Guards.cs:172:33:172:33 | access to parameter o | null |
| Guards.cs:172:34:172:42 | ... == ... | false | Guards.cs:172:34:172:34 | access to parameter o | non-null |
| Guards.cs:172:34:172:42 | ... == ... | true | Guards.cs:172:34:172:34 | access to parameter o | null |
| Guards.cs:176:13:176:21 | ... is ... | false | Guards.cs:176:13:176:13 | access to parameter o | non-null |
| Guards.cs:176:13:176:21 | ... is ... | true | Guards.cs:176:13:176:13 | access to parameter o | null |
| Guards.cs:181:33:181:41 | ... == ... | false | Guards.cs:181:33:181:33 | access to parameter o | non-null |
| Guards.cs:181:33:181:41 | ... == ... | true | Guards.cs:181:33:181:33 | access to parameter o | null |
| Guards.cs:181:33:181:56 | ... ? ... : ... | false | Guards.cs:181:33:181:41 | ... == ... | false |
| Guards.cs:181:33:181:56 | ... ? ... : ... | true | Guards.cs:181:33:181:41 | ... == ... | true |
| Guards.cs:183:36:183:48 | !... | false | Guards.cs:183:37:183:48 | call to method NullTest3 | true |
| Guards.cs:183:36:183:48 | !... | true | Guards.cs:183:37:183:48 | call to method NullTest3 | false |
| Guards.cs:183:37:183:48 | call to method NullTest3 | false | Guards.cs:183:47:183:47 | access to parameter o | non-null |
| Guards.cs:183:37:183:48 | call to method NullTest3 | true | Guards.cs:183:47:183:47 | access to parameter o | null |
| Guards.cs:185:37:185:45 | ... == ... | false | Guards.cs:185:37:185:37 | access to parameter o | non-null |
| Guards.cs:185:37:185:45 | ... == ... | true | Guards.cs:185:37:185:37 | access to parameter o | null |
| Guards.cs:185:37:185:59 | ... ? ... : ... | false | Guards.cs:185:37:185:45 | ... == ... | false |
| Guards.cs:185:37:185:59 | ... ? ... : ... | false | Guards.cs:185:37:185:45 | ... == ... | true |
| Guards.cs:181:34:181:42 | ... == ... | false | Guards.cs:181:34:181:34 | access to parameter o | non-null |
| Guards.cs:181:34:181:42 | ... == ... | true | Guards.cs:181:34:181:34 | access to parameter o | null |
| Guards.cs:181:34:181:57 | ... ? ... : ... | false | Guards.cs:181:34:181:42 | ... == ... | false |
| Guards.cs:181:34:181:57 | ... ? ... : ... | true | Guards.cs:181:34:181:42 | ... == ... | true |
| Guards.cs:183:37:183:49 | !... | false | Guards.cs:183:38:183:49 | call to method NullTest3 | true |
| Guards.cs:183:37:183:49 | !... | true | Guards.cs:183:38:183:49 | call to method NullTest3 | false |
| Guards.cs:183:38:183:49 | call to method NullTest3 | false | Guards.cs:183:48:183:48 | access to parameter o | non-null |
| Guards.cs:183:38:183:49 | call to method NullTest3 | true | Guards.cs:183:48:183:48 | access to parameter o | null |
| Guards.cs:185:38:185:46 | ... == ... | false | Guards.cs:185:38:185:38 | access to parameter o | non-null |
| Guards.cs:185:38:185:46 | ... == ... | true | Guards.cs:185:38:185:38 | access to parameter o | null |
| Guards.cs:185:38:185:60 | ... ? ... : ... | false | Guards.cs:185:38:185:46 | ... == ... | false |
| Guards.cs:185:38:185:60 | ... ? ... : ... | false | Guards.cs:185:38:185:46 | ... == ... | true |
| Guards.cs:189:13:189:25 | !... | false | Guards.cs:189:14:189:25 | call to method NullTest1 | true |
| Guards.cs:189:13:189:25 | !... | true | Guards.cs:189:14:189:25 | call to method NullTest1 | false |
| Guards.cs:189:14:189:25 | call to method NullTest1 | false | Guards.cs:189:24:189:24 | access to parameter s | non-null |

View File

@@ -41,7 +41,7 @@
| Guards.cs:196:31:196:31 | access to parameter s |
| Guards.cs:205:13:205:13 | access to parameter o |
| Guards.cs:208:17:208:17 | access to parameter o |
| Guards.cs:269:11:269:12 | access to parameter o1 |
| Guards.cs:269:13:269:14 | access to parameter o1 |
| Guards.cs:279:17:279:17 | access to parameter o |
| Guards.cs:283:17:283:17 | access to parameter o |
| Guards.cs:287:17:287:17 | access to parameter o |

View File

@@ -6,7 +6,7 @@ using System.Diagnostics;
/// </summary>
public class Splitting
{
void M1(bool b, object o)
void M1(bool b, object? o)
{
if (b)
if (o != null)
@@ -16,7 +16,7 @@ public class Splitting
o.ToString(); // not null guarded
}
string M2(bool b, object o)
string M2(bool b, object? o)
{
if (b)
if (o != null)
@@ -26,7 +26,7 @@ public class Splitting
return o.ToString(); // not null guarded
}
string M3(bool b, object o)
string M3(bool b, object? o)
{
if (b)
if (o == null)
@@ -36,7 +36,7 @@ public class Splitting
return o.ToString(); // not null guarded
}
void M4(bool b, object o)
void M4(bool b, object? o)
{
if (o != null)
{
@@ -47,7 +47,7 @@ public class Splitting
}
}
string M5(bool b, object o)
string M5(bool b, object? o)
{
if (b)
o.ToString(); // not null guarded
@@ -58,7 +58,7 @@ public class Splitting
return o.ToString(); // not null guarded
}
string M6(bool b, object o)
string M6(bool b, object? o)
{
if (b)
o.ToString(); // not null guarded
@@ -69,7 +69,7 @@ public class Splitting
return o.ToString(); // anti-null guarded
}
string M7(bool b, object o, bool b2)
string M7(bool b, object? o, bool b2)
{
if (b)
o.ToString(); // not null guarded
@@ -81,7 +81,7 @@ public class Splitting
return o.ToString(); // not null guarded
}
void M8(bool b, object o)
void M8(bool b, object? o)
{
if (b)
Debug.Assert(o != null);
@@ -91,7 +91,7 @@ public class Splitting
o.ToString(); // not null guarded
}
string M9(bool b, object o)
string M9(bool b, object? o)
{
if (b)
Debug.Assert(o == null);
@@ -100,7 +100,7 @@ public class Splitting
return o.ToString(); // not null guarded
}
void M10(bool b, object o)
void M10(bool b, object? o)
{
Debug.Assert(o != null);
if (b)
@@ -109,7 +109,7 @@ public class Splitting
o.ToString(); // null guarded
}
string M11(bool b, object o)
string M11(bool b, object? o)
{
if (b)
o.ToString(); // not null guarded
@@ -122,7 +122,7 @@ public class Splitting
public void M12(int i, bool b)
{
object o = null;
object? o = null;
do
{
if (o != null)