mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-06 17:46:07 +02:00
codetools: fixed range check in TLinkScanner.SkipTillEndifElse
git-svn-id: trunk@31195 -
This commit is contained in:
parent
1a4778a290
commit
f131c8a242
@ -323,9 +323,9 @@ type
|
|||||||
function ReadIdentifier: string;
|
function ReadIdentifier: string;
|
||||||
function ReadUpperIdentifier: string;
|
function ReadUpperIdentifier: string;
|
||||||
procedure SkipSpace; {$IFDEF UseInline}inline;{$ENDIF}
|
procedure SkipSpace; {$IFDEF UseInline}inline;{$ENDIF}
|
||||||
procedure SkipComment;
|
procedure SkipCurlyComment;
|
||||||
procedure SkipDelphiComment;
|
procedure SkipLineComment;
|
||||||
procedure SkipOldTPComment;
|
procedure SkipRoundComment;
|
||||||
procedure CommentEndNotFound;
|
procedure CommentEndNotFound;
|
||||||
procedure EndComment; {$IFDEF UseInline}inline;{$ENDIF}
|
procedure EndComment; {$IFDEF UseInline}inline;{$ENDIF}
|
||||||
procedure IncCommentLevel; {$IFDEF UseInline}inline;{$ENDIF}
|
procedure IncCommentLevel; {$IFDEF UseInline}inline;{$ENDIF}
|
||||||
@ -1070,20 +1070,20 @@ begin
|
|||||||
'{' :
|
'{' :
|
||||||
begin
|
begin
|
||||||
SrcPos:=p-PChar(Src)+1;
|
SrcPos:=p-PChar(Src)+1;
|
||||||
SkipComment;
|
SkipCurlyComment;
|
||||||
p:=@Src[SrcPos];
|
p:=@Src[SrcPos];
|
||||||
end;
|
end;
|
||||||
'/':
|
'/':
|
||||||
if p[1]='/' then begin
|
if p[1]='/' then begin
|
||||||
SrcPos:=p-PChar(Src)+1;
|
SrcPos:=p-PChar(Src)+1;
|
||||||
SkipDelphiComment;
|
SkipLineComment;
|
||||||
p:=@Src[SrcPos];
|
p:=@Src[SrcPos];
|
||||||
end else
|
end else
|
||||||
break;
|
break;
|
||||||
'(':
|
'(':
|
||||||
if p[1]='*' then begin
|
if p[1]='*' then begin
|
||||||
SrcPos:=p-PChar(Src)+1;
|
SrcPos:=p-PChar(Src)+1;
|
||||||
SkipOldTPComment;
|
SkipRoundComment;
|
||||||
p:=@Src[SrcPos];
|
p:=@Src[SrcPos];
|
||||||
end else
|
end else
|
||||||
break;
|
break;
|
||||||
@ -1391,7 +1391,7 @@ begin
|
|||||||
FLinks[Index]:=Value;
|
FLinks[Index]:=Value;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLinkScanner.SkipComment;
|
procedure TLinkScanner.SkipCurlyComment;
|
||||||
// a normal pascal {} comment
|
// a normal pascal {} comment
|
||||||
var
|
var
|
||||||
p: PChar;
|
p: PChar;
|
||||||
@ -1433,7 +1433,7 @@ begin
|
|||||||
EndComment;
|
EndComment;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLinkScanner.SkipDelphiComment;
|
procedure TLinkScanner.SkipLineComment;
|
||||||
// a // newline comment
|
// a // newline comment
|
||||||
begin
|
begin
|
||||||
CommentStyle:=CommentDelphi;
|
CommentStyle:=CommentDelphi;
|
||||||
@ -1450,7 +1450,7 @@ begin
|
|||||||
EndComment;
|
EndComment;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLinkScanner.SkipOldTPComment;
|
procedure TLinkScanner.SkipRoundComment;
|
||||||
// a (* *) comment
|
// a (* *) comment
|
||||||
var
|
var
|
||||||
p: PChar;
|
p: PChar;
|
||||||
@ -3510,7 +3510,7 @@ procedure TLinkScanner.SkipTillEndifElse(SkippingUntil: TLSSkippingDirective);
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
c1: Char;
|
p: PChar;
|
||||||
begin
|
begin
|
||||||
if FSkippingDirectives<>lssdNone then begin
|
if FSkippingDirectives<>lssdNone then begin
|
||||||
FSkippingDirectives:=SkippingUntil;
|
FSkippingDirectives:=SkippingUntil;
|
||||||
@ -3527,38 +3527,53 @@ begin
|
|||||||
// parse till $else, $elseif or $endif without adding the code to FCleanedSrc
|
// parse till $else, $elseif or $endif without adding the code to FCleanedSrc
|
||||||
FSkipIfLevel:=IfLevel;
|
FSkipIfLevel:=IfLevel;
|
||||||
if (SrcPos<=SrcLen) then begin
|
if (SrcPos<=SrcLen) then begin
|
||||||
|
p:=@Src[SrcPos];
|
||||||
while true do begin
|
while true do begin
|
||||||
c1:=Src[SrcPos];
|
case p^ of
|
||||||
if IsCommentStartChar[c1] then begin
|
'{':
|
||||||
case c1 of
|
begin
|
||||||
'{': begin
|
SrcPos:=p-PChar(Src)+1;
|
||||||
SkipComment;
|
SkipCurlyComment;
|
||||||
if FSkippingDirectives=lssdNone then break;
|
if FSkippingDirectives=lssdNone then break;
|
||||||
end;
|
p:=@Src[SrcPos];
|
||||||
'/': if (Src[SrcPos+1]='/') then begin
|
|
||||||
SkipDelphiComment;
|
|
||||||
if FSkippingDirectives=lssdNone then break;
|
|
||||||
end else
|
|
||||||
inc(SrcPos);
|
|
||||||
'(': if (Src[SrcPos+1]='*') then begin
|
|
||||||
SkipOldTPComment;
|
|
||||||
if FSkippingDirectives=lssdNone then break;
|
|
||||||
end else
|
|
||||||
inc(SrcPos);
|
|
||||||
end;
|
end;
|
||||||
end else if c1='''' then begin
|
'/':
|
||||||
// skip string constant
|
if p[1]='/' then begin
|
||||||
inc(SrcPos);
|
SrcPos:=p-PChar(Src)+1;
|
||||||
while (SrcPos<=SrcLen) and (Src[SrcPos]<>'''') do inc(SrcPos);
|
SkipLineComment;
|
||||||
inc(SrcPos);
|
if FSkippingDirectives=lssdNone then break;
|
||||||
end else begin
|
p:=@Src[SrcPos];
|
||||||
inc(SrcPos);
|
end else
|
||||||
if (SrcPos>SrcLen) and not ReturnFromIncludeFile then begin
|
inc(p);
|
||||||
CommentStartPos:=0;
|
'(':
|
||||||
break;
|
if p[1]='*' then begin
|
||||||
|
SrcPos:=p-PChar(Src)+1;
|
||||||
|
SkipRoundComment;
|
||||||
|
if FSkippingDirectives=lssdNone then break;
|
||||||
|
p:=@Src[SrcPos];
|
||||||
|
end else
|
||||||
|
inc(p);
|
||||||
|
'''':
|
||||||
|
begin
|
||||||
|
// skip string constant
|
||||||
|
inc(p);
|
||||||
|
while p^<>'''' do inc(p);
|
||||||
|
inc(p);
|
||||||
end;
|
end;
|
||||||
|
#0:
|
||||||
|
begin
|
||||||
|
SrcPos:=p-PChar(Src)+1;
|
||||||
|
if (SrcPos>SrcLen) and not ReturnFromIncludeFile then begin
|
||||||
|
CommentStartPos:=0;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
inc(p);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
inc(p);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
SrcPos:=p-PChar(Src)+1;
|
||||||
end;
|
end;
|
||||||
if CommentStartPos>0 then begin
|
if CommentStartPos>0 then begin
|
||||||
CopiedSrcPos:=CommentStartPos-1;
|
CopiedSrcPos:=CommentStartPos-1;
|
||||||
|
Loading…
Reference in New Issue
Block a user