A remainder by 2 is compared with 1, which is false for negative odd numbers
What it finds
The remainder of a negative number is negative in C#: -3 % 2 is -1. A test for odd numbers written as x % 2 == 1 is therefore false for negative odd values; x % 2 != 0 works for both signs. Operands whose declared type is unsigned are left alone.
From the rule's source, odd_test_with_one.rs.
class Parity{ bool Odd(int n) => n % 2 == 1;tx0 reports: n % 2 == 1 misses negative odd numbers bool Odd(uint n) => n % 2 == 1; bool Even(int n) => n % 2 == 0;} 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:
[rules]
"tx0/csharp:odd-test-with-one" = "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/csharp:odd-test-with-one] reason="..."tx0 explain tx0/csharp:odd-test-with-one shows the same in the terminal. Found a false positive? Report it.