On this page
B4109: null check might fail
Catalog status: active. Default severity: error. Stable name: null-check. Family: Executable checks.
A value of an access type may be null, which designates nothing. Reading or writing the object an access value designates (P.all, or a component P.X or P (I), which mean P.all.X and P.all (I)) needs a value that is not null, and so does a subtype with a null exclusion (not null access T, or a parameter declared P : not null Node_Access). The prover found a path on which the value might be null.
Example (Vada)
type Node;
type Node_Access is access Node;
type Node is record
Value : Integer;
Next : Node_Access;
end record;
function Second (List : Node_Access) return Integer is (List.Next.Value);Example (Varc)
type Node;
type Node_Access = *Node;
struct Node {
value: Integer,
next: Node_Access,
}
fn second(list: Node_Access) -> Integer = list.next.value;
What to do (Vada)
Test the value first (if P /= null then), require it in the subprogram's precondition (with Pre => List /= null and then List.Next /= null), or give the parameter or object a null-excluding subtype so that callers must pass a designated object.
What to do (Varc)
Test the value first (if p != null {), or require it in the subprogram's precondition (requires list != null && list.next != null).
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See executable checks, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.