mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 03:00:27 +02:00
SynEdit Folding: protect form accidental deep nesting. (Pascal cuts at 100 recursive nests)
git-svn-id: trunk@19230 -
This commit is contained in:
parent
63703b883c
commit
0ba73e0a74
@ -82,6 +82,7 @@ type
|
||||
function Add(ABlockType: Pointer = nil; IncreaseLevel: Boolean = True):
|
||||
TSynCustomCodeFoldBlock; virtual;
|
||||
procedure Pop(DecreaseLevel: Boolean = True); virtual;
|
||||
function MaxFoldLevel: Integer; virtual;
|
||||
procedure Clear; virtual;
|
||||
procedure Assign(Src: TSynCustomHighlighterRange); virtual;
|
||||
procedure WriteDebugReport;
|
||||
@ -586,7 +587,14 @@ end;
|
||||
|
||||
function TSynCustomHighlighterRange.Add(ABlockType: Pointer;
|
||||
IncreaseLevel: Boolean = True): TSynCustomCodeFoldBlock;
|
||||
var
|
||||
i: LongInt;
|
||||
begin
|
||||
i := MaxFoldLevel;
|
||||
if (i > 0) and (FCodeFoldStackSize >= i) then begin
|
||||
//debugln('Reached MaxFoldLevel, ignoring folds');
|
||||
exit(nil);
|
||||
end;
|
||||
Result := FTop.Child[ABlockType];
|
||||
if IncreaseLevel then
|
||||
inc(FCodeFoldStackSize);
|
||||
@ -607,6 +615,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSynCustomHighlighterRange.MaxFoldLevel: Integer;
|
||||
begin
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
procedure TSynCustomHighlighterRange.Clear;
|
||||
begin
|
||||
FRangeType:=nil;
|
||||
|
@ -170,6 +170,7 @@ type
|
||||
function Add(ABlockType: Pointer = nil; IncreaseLevel: Boolean = True):
|
||||
TSynCustomCodeFoldBlock; override;
|
||||
procedure Pop(DecreaseLevel: Boolean = True); override;
|
||||
function MaxFoldLevel: Integer; override;
|
||||
procedure IncBracketNestLevel;
|
||||
procedure DecBracketNestLevel;
|
||||
procedure DecLastLineCodeFoldLevelFix;
|
||||
@ -2993,9 +2994,9 @@ end;
|
||||
|
||||
function TSynPasSynRange.Add(ABlockType: Pointer; IncreaseLevel: Boolean): TSynCustomCodeFoldBlock;
|
||||
begin
|
||||
if IncreaseLevel then
|
||||
inc(FPasFoldEndLevel);
|
||||
Result := inherited Add(ABlockType, True);
|
||||
if IncreaseLevel and assigned(result) then
|
||||
inc(FPasFoldEndLevel);
|
||||
end;
|
||||
|
||||
procedure TSynPasSynRange.Pop(DecreaseLevel: Boolean);
|
||||
@ -3009,6 +3010,12 @@ begin
|
||||
inherited Pop(True);
|
||||
end;
|
||||
|
||||
function TSynPasSynRange.MaxFoldLevel: Integer;
|
||||
begin
|
||||
// Protect from overly mem consumption, by too many nested folds
|
||||
Result := 100;
|
||||
end;
|
||||
|
||||
procedure TSynPasSynRange.IncBracketNestLevel;
|
||||
begin
|
||||
inc(FBracketNestLevel);
|
||||
|
Loading…
Reference in New Issue
Block a user