* Fix from Henrique Werlang to fix some specific cases where buffer position is not correctly observed/updated

This commit is contained in:
michael 2020-12-15 15:05:25 +00:00
parent a39d168575
commit d6c9909688

View File

@ -1293,6 +1293,7 @@ type
procedure HandleString; procedure HandleString;
procedure HandleMinus; procedure HandleMinus;
procedure HandleUnknown; procedure HandleUnknown;
procedure GotoToNextChar;
public public
// Input stream is expected to be UTF16 ! // Input stream is expected to be UTF16 !
constructor Create(Stream: TStream); constructor Create(Stream: TStream);
@ -9909,7 +9910,6 @@ begin
FPos := 0; FPos := 0;
FBufLen := CharsRead; FBufLen := CharsRead;
FEofReached:=CharsRead = 0; FEofReached:=CharsRead = 0;
FBuf[CharsRead] := #0;
end; end;
procedure TParser.CheckLoadBuffer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE} procedure TParser.CheckLoadBuffer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
@ -9921,8 +9921,8 @@ end;
procedure TParser.ProcessChar; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE} procedure TParser.ProcessChar; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
begin begin
fLastTokenStr:=fLastTokenStr+fBuf[fPos]; fLastTokenStr:=fLastTokenStr+fBuf[fPos];
inc(fPos);
CheckLoadBuffer; GotoToNextChar;
end; end;
function TParser.IsNumber: boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE} function TParser.IsNumber: boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
@ -9962,23 +9962,19 @@ begin
while IsAlphaNum do while IsAlphaNum do
begin begin
Result:=Result+fBuf[fPos]; Result:=Result+fBuf[fPos];
inc(fPos);
CheckLoadBuffer; GotoToNextChar;
end; end;
end; end;
procedure TParser.HandleNewLine; procedure TParser.HandleNewLine;
begin begin
if fBuf[fPos]=#13 then //CR if fBuf[fPos]=#13 then //CR
begin GotoToNextChar;
inc(fPos);
CheckLoadBuffer; if fBuf[fPos]=#10 then //LF
end; GotoToNextChar;
if fBuf[fPos]=#10 then
begin
inc(fPos); //CR LF or LF
CheckLoadBuffer;
end;
inc(fSourceLine); inc(fSourceLine);
fDeltaPos:=-(fPos-1); fDeltaPos:=-(fPos-1);
end; end;
@ -9991,15 +9987,12 @@ end;
procedure TParser.SkipSpaces; procedure TParser.SkipSpaces;
begin begin
while fBuf[fPos] in [' ',#9] do begin while not FEofReached and (fBuf[fPos] in [' ',#9]) do GotoToNextChar;
inc(fPos);
CheckLoadBuffer;
end;
end; end;
procedure TParser.SkipWhitespace; procedure TParser.SkipWhitespace;
begin begin
while true do while not FEofReached do
begin begin
case fBuf[fPos] of case fBuf[fPos] of
' ',#9 : SkipSpaces; ' ',#9 : SkipSpaces;
@ -10056,8 +10049,9 @@ begin
if (fBuf[fPos] in ['s','S','d','D','c','C']) then //single, date, currency if (fBuf[fPos] in ['s','S','d','D','c','C']) then //single, date, currency
begin begin
fFloatType:=fBuf[fPos]; fFloatType:=fBuf[fPos];
inc(fPos);
CheckLoadBuffer; GotoToNextChar;
fToken:=toFloat; fToken:=toFloat;
end end
else fFloatType:=#0; else fFloatType:=#0;
@ -10067,8 +10061,7 @@ procedure TParser.HandleHexNumber;
var valid : boolean; var valid : boolean;
begin begin
fLastTokenStr:='$'; fLastTokenStr:='$';
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
valid:=false; valid:=false;
while IsHexNum do while IsHexNum do
begin begin
@ -10083,22 +10076,20 @@ end;
function TParser.HandleQuotedString: string; function TParser.HandleQuotedString: string;
begin begin
Result:=''; Result:='';
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
while true do while true do
begin begin
case fBuf[fPos] of case fBuf[fPos] of
#0 : ErrorStr(SParserUnterminatedString); #0 : ErrorStr(SParserUnterminatedString);
#13,#10 : ErrorStr(SParserUnterminatedString); #13,#10 : ErrorStr(SParserUnterminatedString);
'''' : begin '''' : begin
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
if fBuf[fPos]<>'''' then exit; if fBuf[fPos]<>'''' then exit;
end; end;
end; end;
Result:=Result+fBuf[fPos]; Result:=Result+fBuf[fPos];
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
end; end;
end; end;
@ -10108,15 +10099,13 @@ var
i : integer; i : integer;
begin begin
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
// read a word number // read a word number
i:=0; i:=0;
while IsNumber and (i<high(word)) do while IsNumber and (i<high(word)) do
begin begin
i:=i*10+Ord(fBuf[fPos])-ord('0'); i:=i*10+Ord(fBuf[fPos])-ord('0');
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
end; end;
if i>high(word) then i:=0; if i>high(word) then i:=0;
Result:=Char(i); Result:=Char(i);
@ -10149,8 +10138,7 @@ end;
procedure TParser.HandleMinus; procedure TParser.HandleMinus;
begin begin
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
if IsNumber then if IsNumber then
begin begin
HandleNumber; HandleNumber;
@ -10167,14 +10155,13 @@ procedure TParser.HandleUnknown;
begin begin
fToken:=toUnknown; fToken:=toUnknown;
fLastTokenStr:=fBuf[fPos]; fLastTokenStr:=fBuf[fPos];
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
end; end;
constructor TParser.Create(Stream: TStream); constructor TParser.Create(Stream: TStream);
begin begin
fStream:=Stream; fStream:=Stream;
SetLength(fBuf,Succ(ParseBufSize)); SetLength(fBuf,ParseBufSize);
fBufLen:=0; fBufLen:=0;
fPos:=0; fPos:=0;
fDeltaPos:=1; fDeltaPos:=1;
@ -10188,6 +10175,13 @@ begin
NextToken; NextToken;
end; end;
procedure TParser.GotoToNextChar;
begin
Inc(FPos);
CheckLoadBuffer;
end;
destructor TParser.Destroy; destructor TParser.Destroy;
Var Var
@ -10240,13 +10234,11 @@ begin
while IsHexNum do while IsHexNum do
begin begin
b:=(GetHexValue(fBuf[fPos]) shl 4); b:=(GetHexValue(fBuf[fPos]) shl 4);
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
if not IsHexNum then if not IsHexNum then
Error(SParserUnterminatedBinValue); Error(SParserUnterminatedBinValue);
b:=b or GetHexValue(fBuf[fPos]); b:=b or GetHexValue(fBuf[fPos]);
inc(fPos); GotoToNextChar;
CheckLoadBuffer;
outbuf[i]:=b; outbuf[i]:=b;
inc(i); inc(i);
if i>=ParseBufSize then if i>=ParseBufSize then
@ -10266,7 +10258,7 @@ function TParser.NextToken: TParserToken;
Procedure SetToken(aToken : TParserToken); Procedure SetToken(aToken : TParserToken);
begin begin
FToken:=aToken; FToken:=aToken;
Inc(fPos); GotoToNextChar;
end; end;
begin begin