The result of & or | with a constant is compared with a value it can never equal
What it finds
(flags & 0x0f) == 0x10 or (mode | 4) == 2: the value compared with has bits that the masked side can never have, or lacks bits it always has, so the comparison is always false, or with != always true. Usually the mask or the value is wrong.
The mask and the value must be constants written with literals and not negative.
From the rule's source, impossible_mask_comparison.rs.
int flags_set(int flags){ if ((flags & 0x0f) == 0x10)tx0 reports: the result of & with 0xf can never equal 0x10, so this is always false return 1; if ((flags | 4) != 2)tx0 reports: always true return 2; return (flags & 0x0f) == 0x01;} 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-mask-comparison" = "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-mask-comparison] reason="..."tx0 explain tx0/c:impossible-mask-comparison shows the same in the terminal. Found a false positive? Report it.