Two comparisons of the same value with constants make a condition that is always false or always true
What it finds
x < 0 && x > 10 is never true and x > 5 || x < 10 always is: the two ranges do not overlap, or together cover every value. Usually one comparison is the wrong way round or && and || are swapped.
Both operands of the && or || must compare the same expression, without calls or side effects, with integer constants written with literals.
From the rule's source, impossible_condition.rs.
int range(int x, int y){ if (x < 0 && x > 10)tx0 reports: this condition is always false return 1; if (x > 5 || x < 10)tx0 reports: this condition is always true return 2; if (x == 1 && x == 2)tx0 reports: this condition is always false return 3; if (x != 1 || x != 2)tx0 reports: this condition is always true return 4; if (x > 0 && x < 10) return 5; if (x < 0 || x > 10) return 6; if (x < 0 && y > 10) return 7; return 0;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/c:impossible-condition" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:impossible-condition] reason="..."tx0 explain tx0/c:impossible-condition shows the same in the terminal. Found a false positive? Report it.