The result of strcmp or memcmp is used as a truth value, which is true when the operands differ

tx0/c:compare-result-as-conditionallwarningstyle/conventionsdepth faststyle

What it finds

if (strcmp(a, b)) or if (!memcmp(p, q, n)): these functions return 0 when their operands are equal, so used as a truth value the test reads as the opposite of what it does. Comparing the result with 0, strcmp(a, b) != 0, says which way it goes.

From the rule's source, compare_result_as_condition.rs.

Example from the rule's tests
#include <string.h> int same(const char *a, const char *b){  if (strcmp(a, b))tx0 reports: strcmp returns 0 for equal operands    return 0;  if (!memcmp(a, b, 4))tx0 reports: memcmp returns 0    return 1;  return strcmp(a, b) == 0;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:compare-result-as-condition" = "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:compare-result-as-condition] reason="..."

tx0 explain tx0/c:compare-result-as-condition shows the same in the terminal. Found a false positive? Report it.