Open
Description
Prerequisites
- This bug is in SonarDelphi, not SonarQube or my Delphi code.
- This bug has not already been reported.
SonarDelphi version
1.0.0
SonarQube version
No response
Issue description
This rule is particuliarly important, because the Delphi compiler itself misses so many cases on uninitialized variables, and this causes nasty real-world bugs. I hoped you could do better. (Indeed, if you offer this rule, it is because you are aware of the compiler's failures, so it is meant to do better!)
But no, here is a very basic program that passes the scan.
Steps to reproduce
Run the scanner on the provided mini project. The uninitialized variable in Main is not detected.
It should be done either using default
: LThing := Default(TThing)
, or using a constructor (if one was defined).
I report it as a bug because this case is really a basic one.
Minimal Delphi code exhibiting the issue
program BugReport;
{$APPTYPE CONSOLE}
type
TThing = record
FThing: Integer;
procedure SetThing(AVal: Integer);
function GetThing: Integer;
end;
function TThing.GetThing: Integer;
begin
Result := FThing;
end;
procedure TThing.SetThing(AVal: Integer);
begin
FThing := AVal;
end;
procedure Main;
var
LThing: TThing;
begin
WriteLn(LThing.GetThing); // used but not initialized, random output
LThing.SetThing(0);
WriteLn(LThing.GetThing);
end;
begin
Main;
ReadLn;
end.