mirror of
https://github.com/github/codeql.git
synced 2026-05-04 21:25:44 +02:00
C#: Improve empty collection check to not report on collections with property writes
This commit is contained in:
@@ -152,6 +152,21 @@ class Test
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void f9()
|
||||
{
|
||||
var l1 = new MyList(); // BAD
|
||||
var x1 = l1[0];
|
||||
|
||||
var l2 = new MyList(); // GOOD
|
||||
var x2 = l2[0];
|
||||
l2.Prop = 42;
|
||||
}
|
||||
|
||||
class MyList : List<int>
|
||||
{
|
||||
public int Prop { get { return 0; } set { Add(value); } }
|
||||
}
|
||||
}
|
||||
|
||||
// semmle-extractor-options: /r:System.Collections.dll
|
||||
|
||||
@@ -8,4 +8,5 @@
|
||||
| ReadOnlyContainer.cs:91:13:91:14 | v8 | The contents of this container are never initialized. |
|
||||
| ReadOnlyContainer.cs:96:13:96:14 | v9 | The contents of this container are never initialized. |
|
||||
| ReadOnlyContainer.cs:99:13:99:15 | v10 | The contents of this container are never initialized. |
|
||||
| ReadOnlyContainer.cs:121:13:121:15 | v11 | The contents of this container are never initialized. |
|
||||
| ReadOnlyContainer.cs:121:13:121:15 | v11 | The contents of this container are never initialized. |
|
||||
| ReadOnlyContainer.cs:158:13:158:14 | l1 | The contents of this container are never initialized. |
|
||||
|
||||
Reference in New Issue
Block a user