A pointer is compared with zero by <, <=, > or >= instead of being tested for NULL
What it finds
if (p > 0) or while (ptr >= 0): ordering a pointer against a null pointer constant is not defined by the standard, and where it compiles, p >= 0 is always true and p > 0 merely tests for NULL. p != NULL was meant.
The pointer must be a variable declared as a pointer in the file, compared with the literal 0 by <, <=, > or >=.
From the rule's source, pointer_ordered_with_zero.rs.
int walk(char *p, int n){ if (p > 0)tx0 reports: only tests whether p is not NULL n++; if (p >= 0)tx0 reports: is always true n++; if (n > 0 && p != 0) n++; return n;} 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:pointer-ordered-with-zero" = "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:pointer-ordered-with-zero] reason="..."tx0 explain tx0/c:pointer-ordered-with-zero shows the same in the terminal. Found a false positive? Report it.