Skip to content

Incorrect Logic¶

Rule ID¶

MI105

Definition¶

The software attempts to execute code which is either logically incorrect or was likely not the original intention of the programmer.

Example¶

See one of the applicable code examples from CWE.

1
2
3
4
5
6
7
8
9
String s = null;
if (b) {
  s = "Yes";
  return;
}

if (s != null) {
  Dead();
}

The condition for the second if statement is impossible to satisfy. It requires that the variables be non-null, while on the only path where s can be assigned a non-null value there is a return statement.

References¶

  • Common Weakness Enumeration: CWE-115
  • Common Weakness Enumeration: CWE-393
  • Common Weakness Enumeration: CWE-561