A pointer is dereferenced where it is NULL on every path

tx0/cpp:null-dereferencedefaultwarningreliability/null-safetydepth fastbug, cwe-476

What it finds

if (p == NULL && p->len > 0), if (!p) { log(p->name); }, or p = NULL; followed by p->next = q on every path: the pointer is dereferenced where it is NULL on every path that reaches the dereference, which crashes.

``cpp if (!entry) { fprintf(stderr, "no entry %s\n", entry->name); // entry is NULL here return -1; } ``

The rule follows each function on its paths, keeping apart up to four of them. A pointer is NULL by the constant NULL or 0, or by the test that took the path, and is reported only where it is NULL on all the paths that get there. Local variables and parameters are followed as SSA values; a variable whose address is taken is not. Functions with constructs the lowering does not understand are skipped.

From the rule's source, null_dereference.rs.

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:

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

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