43 lines
1.1 KiB
Plaintext
43 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Conditional expressions which are always `true` or `false` can lead to https://en.wikipedia.org/wiki/Unreachable_code[unreachable code].
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,text]
|
|
----
|
|
a = false;
|
|
if (a) { // Noncompliant
|
|
doSomething(); // never executed
|
|
}
|
|
|
|
if (!a || b) { // Noncompliant; "!a" is always "true", "b" is never evaluated
|
|
doSomething();
|
|
} else {
|
|
doSomethingElse(); // never executed
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* CWE - https://cwe.mitre.org/data/definitions/570[CWE-570 - Expression is Always False]
|
|
* CWE - https://cwe.mitre.org/data/definitions/571[CWE-571 - Expression is Always True]
|
|
* https://wiki.sei.cmu.edu/confluence/x/5dUxBQ[CERT, MSC12-C.] - Detect and remove code that has no effect or is never executed
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Change this condition so that it does not always evaluate to "[true|false]"; some subsequent code is never executed.
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
endif::env-github,rspecator-view[]
|