2021-06-08 14:23:48 +02:00
|
|
|
Failing to null-test the argument to an ``++equals++`` method could result in a null pointer dereference, leading to runtime failures.
|
|
|
|
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public bool Equals (object obj) { // Noncompliant
|
|
|
|
return getValue() == obj.getValue() ;
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
public bool Equals (object obj) {
|
|
|
|
if (obj == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return getValue() == obj.getValue() ;
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
== See
|
|
|
|
|
2021-10-28 10:07:16 +02:00
|
|
|
* https://cwe.mitre.org/data/definitions/476.html[MITRE, CWE-476] - NULL Pointer Dereference
|
2021-06-08 14:23:48 +02:00
|
|
|
|