A comparison is compared again as in mathematics, but C compares its 0 or 1 result

tx0/c:chained-comparisonstrictwarningreliability/logicdepth fastbug

What it finds

if (0 <= x < 10): comparisons do not chain in C. The first gives 0 or 1, which is then compared with the bound, so the condition does not test a range; 0 <= x && x < 10 was meant.

The operand of a <, <=, > or >= must be another such comparison without parentheses around it. a < b > c is left alone, which is how a C++ template argument in a header reads to a C parser.

From the rule's source, chained_comparison.rs.

Example from the rule's tests
int in_range(int x, int lo, int hi){  if (lo <= x <= hi)tx0 reports: the first comparison gives 0 or 1    return 1;  return lo <= x && x <= hi && (x < hi) == 1;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:chained-comparison" = "warning"

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:chained-comparison] reason="..."

tx0 explain tx0/c:chained-comparison shows the same in the terminal. Found a false positive? Report it.