A semicolon right after the condition of an if is its whole body
What it finds
if (x == 1); followed by a block: the ; right after the condition is the whole body of the if, so the block after it runs whatever the condition.
Only a ; on the line of the condition, with no comment before it, counts, and only for an if without else. A condition with a call is left alone: if (write(...)); is a way of ignoring a result that the compiler warns about.
From the rule's source, empty_if_body.rs.
#include <unistd.h> int f(int x, int fd){ int r = 0; if (x == 1);tx0 reports: the ; after the condition is the whole body of the if { r = 1; } if (x > 2) ; if (x > 3) /* nothing */; if (write(fd, "", 0)); if (x > 4); else r = 2; while (x-- > 0); if (x) r = 3; return r;} 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:empty-if-body" = "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:empty-if-body] reason="..."tx0 explain tx0/c:empty-if-body shows the same in the terminal. Found a false positive? Report it.