A bit-field of one bit has a signed type, so it holds 0 and -1 rather than 0 and 1
What it finds
int ready : 1;: a one-bit field of a signed type can hold only 0 and -1, so setting it to 1 and testing ready == 1 fails; and whether plain int is signed in a bit-field depends on the compiler. unsigned int or bool holds 0 and 1.
From the rule's source, signed_one_bit_field.rs.
#include <stdbool.h> struct flags { int ready : 1;tx0 reports: this one-bit field is signed and holds 0 and -1 signed int done : 1;tx0 reports: this one-bit field is signed and holds 0 and -1 unsigned int ok : 1; bool set : 1; int mode : 2;}; 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/c:signed-one-bit-field" = "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:signed-one-bit-field] reason="..."tx0 explain tx0/c:signed-one-bit-field shows the same in the terminal. Found a false positive? Report it.