mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
23 lines
728 B
Plaintext
23 lines
728 B
Plaintext
/**
|
|
* @name Null argument to Equals(object)
|
|
* @description Calls of the form 'o.Equals(null)' always return false for non-null 'o', and
|
|
* throw a 'NullReferenceException' when 'o' is null.
|
|
* @kind problem
|
|
* @problem.severity warning
|
|
* @precision high
|
|
* @id cs/null-argument-to-equals
|
|
* @tags quality
|
|
* reliability
|
|
* correctness
|
|
*/
|
|
|
|
import csharp
|
|
import semmle.code.csharp.frameworks.System
|
|
|
|
from MethodCall c, EqualsMethod equals
|
|
where
|
|
c.getTarget().getUnboundDeclaration() = equals and
|
|
c.getArgument(0) instanceof NullLiteral and
|
|
not c.getQualifier().getType() instanceof NullableType
|
|
select c, "Equality test with 'null' will never be true, but may throw a 'NullReferenceException'."
|