x % 2 == 1 tests a signed value for being odd, which is false for negative odd numbers

tx0/c:odd-test-on-signedrecommendedwarningreliability/arithmeticdepth fastbug

What it finds

if (n % 2 == 1): for a negative odd n, n % 2 is -1, so the test fails. n % 2 != 0 or n & 1 tests oddness for every value.

The value must be a variable declared with a signed integer type in the file.

From the rule's source, odd_test_on_signed.rs.

Example from the rule's tests
int count_odd(const int *items, int n){  int count = 0;  for (int i = 0; i < n; i++) {    int v = items[i];    if (v % 2 == 1)tx0 reports: for a negative odd v, v % 2 is -1      count++;  }  unsigned u = (unsigned)n;  return count + (u % 2 == 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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:odd-test-on-signed" = "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:odd-test-on-signed] reason="..."

tx0 explain tx0/c:odd-test-on-signed shows the same in the terminal. Found a false positive? Report it.