I’m tracing a bug deep in 3rd party code, where the statement
fStringLen := Str - fToIdent;
gives a run-time error, with:
Str
is a PChar private function parameter, it is ” at this moment
(Initially not empty but Inc(Str) executed till the end of a loop)- fStringlen is an integer private property, value 0
- fToIdent is a PChar private property, it shows
nil {%0}
in the inspector window:
It’s unclear at this moment whether anything has been done to the fToIndent
PChar property (it does not have a setter that I can put a breakpoint on), or if this is just the initial state after creation of its object.
There is a somewhat older 32-bit version of our software with an older version of the 3rd party software, but where that piece of code is identical. The values are the same if I run the code, but then there is no range check error.
FWIW, this is the code:
function TdaSynHighlighterSQL.HashKey(Str: PChar): Integer;
// called with Str = 'absolute'
var
FoundDoubleMinus: Boolean;
function GetOrd: Integer;
begin
case Str^ of
'_': Result := 1;
'a'..'z': Result := 2 + Ord(Str^) - Ord('a');
'A'..'Z': Result := 2 + Ord(Str^) - Ord('A');
'@':
if fDialect in [sqlMSSQL7, sqlMSSQL2K] then
Result := 24
else
Result := 0;
else Result := 0;
end;
end;
begin
Result := 0;
while IsIdentChar(Str^) do // Always true until Str=''
begin
FoundDoubleMinus := (Str^ = '-') and ((Str + 1)^ = '-');
if FoundDoubleMinus then Break;
Result := (2 * Result + GetOrd) and $FFFFFF;
inc(Str);
end;
Result := Result and $FF; // 255
fStringLen := Str - fToIdent;
end;
How to best fix this?
I find it strange that this code still would not be 64-bit proof