A pointer that a test found NULL on some path is dereferenced on that path

tx0/cpp:null-on-some-pathstrictwarningreliability/null-safetydepth fastbug, cwe-476

What it finds

if (p == NULL) log("missing"); ... p->len: the code tests a pointer for NULL, and a path on which the test found it NULL goes on to dereference it. Either the test or the missing return after it is wrong.

``cpp if (cfg == NULL) fprintf(stderr, "no configuration\n"); size = cfg->size; // crashes when cfg is NULL ``

The rule follows each function on its paths as null-dereference does, and reports a dereference that is NULL on some of the paths that reach it, but not on all; those are null-dereference's. The NULL comes from a test or from the constant. Conditions that tie the pointer to another variable, as len = p ? strlen(p) : 0 does, are not followed, so some reports are paths that cannot happen; the rule is in the strict tier.

From the rule's source, null_on_some_path.rs.

Turn it on, off or suppress it

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

tx0.toml
[rules]
"tx0/cpp:null-on-some-path" = "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/cpp:null-on-some-path] reason="..."

tx0 explain tx0/cpp:null-on-some-path shows the same in the terminal. Found a false positive? Report it.