The result of strcmp or memcmp is compared with 1 or -1, though only its sign is defined
What it finds
if (strcmp(a, b) == 1): the comparison functions return a negative number, zero or a positive number, of any size, and many libraries return the difference of the first bytes that differ. Testing for exactly 1 or -1 misses most results; > 0 or < 0 says what is meant.
From the rule's source, comparison_result_as_one.rs.
#include <string.h> int order(const char *a, const char *b){ if (strcmp(a, b) == 1)tx0 reports: strcmp may return any positive or negative number, not just 1 return 1; if (memcmp(a, b, 4) != -1)tx0 reports: memcmp may return any positive or negative number, not just -1 return 2; return strcmp(a, b) > 0;} 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:comparison-result-as-one" = "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:comparison-result-as-one] reason="..."tx0 explain tx0/c:comparison-result-as-one shows the same in the terminal. Found a false positive? Report it.