I found a bug that had been sitting in my program for a long time, and the compiler did not give any run-time errors...

I found a bug that had been sitting in my program for a long time, and the compiler did not give any run-time errors for it. The compiler does not perform a range check when assigning a value from the Variant variable. Be careful!

Demo code:
program VariantError;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var
v: Variant;
w: Word;
begin
v := $10000;
w := v; // No Range check error
Writeln(w); // "0" ???
end.

https://quality.embarcadero.com/browse/RSP-20956
https://quality.embarcadero.com/browse/RSP-20956

Comments