Rule Definition
Unconditional if statements create results that are not expected by the developer.
If the 'if' statement always resolves to FALSE then the enclosed code block is never executed on the other hand an 'if' statement always resolving to TRUE makes the code block to be always executed which indicates redundancy in code and fault in logic.
One of the possible reasons this happens is that developer tries to debug the code and replaces the condition but later forgets to revert the condition back to a valid one.
This rule focus on conditional testing boolean directly, like "if(true)", or variable initialized but not modified afterward.
Remediation
Review the code and remove the unconditional statement OR add a valid condition.
Violation Code Sample
bool isValidProduct = false;
bool isValidCustomer = true;
if(isValidProduct)
{
foo(); //Violation: Function is never called
}
if(isValidCustomer)
{
foo(); //Violation: Function is always called
}
Fixed Code Sample
Reference
https://cwe.mitre.org/data/definitions/570.html
https://cwe.mitre.org/data/definitions/571.html
https://cwe.mitre.org/data/definitions/489.html
Related Technologies
Technical Criterion
CWE-571 - Expression is Always True
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.