- Sat 08 March 2014
- adacontrol
- Tero Koskinen
- #parameters, #codereview
Have you ever accidentally written code like this?
procedure Example_Proc (X : out Boolean) is
begin
null; -- Do something, but do not touch X
end Example_Proc;
with Example_Proc;
procedure Main is
My_Flag : Boolean;
begin
Example_Proc (My_Flag);
end Main;
In the above code, parameter X with mode "out" is left untouched. Because of this, value of My_Flag is undefined after Example_Proc (My_Flag) call.
To prevent mistakes like this, you can use Adacontrol and a rule:
check improper_initialization (out_parameter);
With the rule, Adacontrol will warn you about your mistake:
$ adactl -f rules.aru example_proc.adb example_proc.ads main.adb example_proc.adb:1:25: Error: IMPROPER_INITIALIZATION: out parameter "X" not safely initialized $