On this page
B3001: variable might be read before it is assigned
Catalog status: active. Default severity: error. Stable name: uninitialised-read. Family: Flow and effects.
Flow analysis (Verada's Bronze level) follows every path through a subprogram. On some path this variable is read before anything was assigned to it, so its value would be whatever was in memory. Verada requires whole objects to be initialised: assigning one element of an array counts as reading the array.
Example (Vada)
Total : Integer;
begin
Total := Total + Count; -- Total has no value yetExample (Varc)
var total: Integer;
total = total + count; // total has no value yet
What to do (Vada)
Give the variable an initial value where it is declared (Total : Integer := 0;), or assign it on every path before the read. For arrays, initialise the whole array first, for example with (others => 0).
What to do (Varc)
Give the variable an initial value where it is declared (var total: Integer = 0;), or assign it on every path before the read. For arrays, initialise the whole array first, for example with (others: 0).
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See flow and effects, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.