From 4aebbac9ebff0c97c79662eede7e264e2bbce722 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Wed, 2 Dec 2026 11:32:51 +0100 Subject: [PATCH] C#: Account for bogus nullness information from the extractor --- csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll | 3 ++- .../library-tests/controlflow/guards/AbstractValue.expected | 3 --- csharp/ql/test/library-tests/csharp8/NullableRefTypes.expected | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll b/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll index 2c214b11e904..d0c8f737206c 100644 --- a/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll +++ b/csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll @@ -855,7 +855,8 @@ module Internal { or e instanceof ArrayCreation or - e.hasNotNullFlowState() + e.hasNotNullFlowState() and + not nullValueImplied(e) or e.hasValue() and exists(Expr stripped | stripped = e.stripCasts() | diff --git a/csharp/ql/test/library-tests/controlflow/guards/AbstractValue.expected b/csharp/ql/test/library-tests/controlflow/guards/AbstractValue.expected index 712e379e3313..10ca9fea4c10 100644 --- a/csharp/ql/test/library-tests/controlflow/guards/AbstractValue.expected +++ b/csharp/ql/test/library-tests/controlflow/guards/AbstractValue.expected @@ -659,7 +659,6 @@ | not null | Guards.cs:108:9:108:15 | access to type Console | | not null | Guards.cs:108:9:108:43 | call to method WriteLine | | not null | Guards.cs:108:27:108:27 | access to parameter g | -| not null | Guards.cs:108:27:108:36 | access to property Property | | not null | Guards.cs:113:21:113:21 | access to parameter g | | not null | Guards.cs:114:14:114:14 | access to parameter g | | not null | Guards.cs:114:14:114:23 | access to property Property | @@ -684,7 +683,6 @@ | not null | Guards.cs:119:9:119:15 | access to type Console | | not null | Guards.cs:119:9:119:43 | call to method WriteLine | | not null | Guards.cs:119:27:119:27 | access to parameter g | -| not null | Guards.cs:119:27:119:36 | access to property Property | | not null | Guards.cs:124:13:124:14 | access to local variable b1 | | not null | Guards.cs:124:13:124:30 | Boolean b1 = ... | | not null | Guards.cs:124:18:124:30 | call to method Equals | @@ -706,7 +704,6 @@ | not null | Guards.cs:156:24:156:24 | access to local variable a | | not null | Guards.cs:157:18:157:19 | "" | | not null | Guards.cs:158:24:158:24 | access to parameter o | -| not null | Guards.cs:159:18:159:21 | null | | not null | Guards.cs:162:24:162:24 | access to parameter o | | not null | Guards.cs:168:13:168:41 | !... | | not null | Guards.cs:168:14:168:19 | access to type String | diff --git a/csharp/ql/test/library-tests/csharp8/NullableRefTypes.expected b/csharp/ql/test/library-tests/csharp8/NullableRefTypes.expected index d6965f85da5c..186ebec7bc30 100644 --- a/csharp/ql/test/library-tests/csharp8/NullableRefTypes.expected +++ b/csharp/ql/test/library-tests/csharp8/NullableRefTypes.expected @@ -78,7 +78,6 @@ nonNullExpressions | NullableRefTypes.cs:87:9:87:9 | access to local variable x | | NullableRefTypes.cs:88:9:88:9 | access to local variable y | | NullableRefTypes.cs:88:9:88:14 | ... = ... | -| NullableRefTypes.cs:88:13:88:13 | access to local variable x | | NullableRefTypes.cs:88:13:88:14 | ...! | assignableTypes | NullableRefTypes.cs:9:14:9:14 | A | NullableRefTypes.cs:6:7:6:13 | MyClass? | ? |