View Issue Details

IDProjectCategoryView StatusLast Update
0031049LazarusPatchpublic2017-01-24 06:14
ReporterPascal RiekenbergAssigned ToMartin Friebe 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindowsOS Version10
Product Version1.7 (SVN)Product Build 
Target Version1.8Fixed in Version1.8 
Summary0031049: Array FFoldColorInfos in SynEditMarkupFoldColoring is too small/not dynamic
Descriptionif you add a long if-then-else of the following type to your code while
color outlining is active the index to the array FFoldColorInfos will be out of range soon:

if a then begin
  b
end else if c then begin
  d
end else if e then begin
  f
end else if g then begin
  .
  .
end else if y then begin
  z
end;
TagsNo tags attached.
Fixed in Revision53987
LazTarget1.8
Widgetset
Attached Files
  • syneditmarkupfoldcoloring.pas.patch (2,370 bytes)
    Index: syneditmarkupfoldcoloring.pas
    ===================================================================
    --- syneditmarkupfoldcoloring.pas	(revision 53511)
    +++ syneditmarkupfoldcoloring.pas	(working copy)
    @@ -82,11 +82,12 @@
         FFirstCharacterColumnCache: Array of Byte;
         FEndLineCache: Array of Integer;
         FCacheCount,
    -    FCacheCapacity: Integer;
    +    FCacheCapacity,
    +    FFoldColorInfosCount,
    +    FFoldColorInfosCapacity: Integer;
     
         FDefaultGroup: integer;
         FFoldColorInfos: TMarkupFoldColorInfos;
    -    FFoldColorInfosCount: Integer;
     
         Colors : array of TColor;
         FPreparedRow: integer;
    @@ -95,6 +96,7 @@
         procedure DoMarkupParentCloseFoldAtRow(aRow: Integer);
         procedure SetDefaultGroup(AValue: integer);
         procedure SetCacheCount(pNewCount: Integer);
    +    procedure SetFoldColorInfosCount(pNewCount: Integer);
         procedure InitCache;
         procedure ClearCache;
         property FirstCharacterColumn[index: Integer]: Byte read GetFirstCharacterColumn;
    @@ -150,6 +152,7 @@
       FDefaultGroup := 0;
       FFoldColorInfosCount := 0;
       SetLength(FFoldColorInfos, 50);
    +  FFoldColorInfosCapacity := 50;
     
       FNestList := TLazSynEditNestedFoldsList.Create(Lines, FHighlighter);
       FNestList.ResetFilter;
    @@ -298,7 +301,7 @@
             DebugLn('!!! TSynEditMarkupFoldColors.DoMarkupParentFoldAtRow: FEndLine-Array too small !!!');
           end;
         end;
    -    inc(FFoldColorInfosCount);
    +    SetFoldColorInfosCount(FFoldColorInfosCount + 1);
         with FFoldColorInfos[FFoldColorInfosCount - 1] do begin
     
           SrcNode:= ANode; //needed by close node
    @@ -403,7 +406,7 @@
            FFoldColorInfos[j].Border := False
           end;
     
    -    inc(FFoldColorInfosCount);
    +    SetFoldColorInfosCount(FFoldColorInfosCount + 1);
         with FFoldColorInfos[FFoldColorInfosCount - 1] do begin
           Border := False;
           SrcNode:= ANode; //needed by close node
    @@ -604,6 +607,18 @@
       FCacheCount := pNewCount;
     end;
     
    +procedure TSynEditMarkupFoldColors.SetFoldColorInfosCount(pNewCount: Integer);
    +var
    +  i: Integer;
    +begin
    +  if pNewCount > FFoldColorInfosCapacity then begin
    +    // expand array
    +    FFoldColorInfosCapacity := pNewCount + 49;
    +    SetLength(FFoldColorInfos, FFoldColorInfosCapacity);
    +  end;
    +  FFoldColorInfosCount := pNewCount;
    +end;
    +
     procedure TSynEditMarkupFoldColors.InitCache;
     begin
       if Assigned(FNestList) then
    

Activities

Pascal Riekenberg

2016-12-01 22:29

reporter  

syneditmarkupfoldcoloring.pas.patch (2,370 bytes)
Index: syneditmarkupfoldcoloring.pas
===================================================================
--- syneditmarkupfoldcoloring.pas	(revision 53511)
+++ syneditmarkupfoldcoloring.pas	(working copy)
@@ -82,11 +82,12 @@
     FFirstCharacterColumnCache: Array of Byte;
     FEndLineCache: Array of Integer;
     FCacheCount,
-    FCacheCapacity: Integer;
+    FCacheCapacity,
+    FFoldColorInfosCount,
+    FFoldColorInfosCapacity: Integer;
 
     FDefaultGroup: integer;
     FFoldColorInfos: TMarkupFoldColorInfos;
-    FFoldColorInfosCount: Integer;
 
     Colors : array of TColor;
     FPreparedRow: integer;
@@ -95,6 +96,7 @@
     procedure DoMarkupParentCloseFoldAtRow(aRow: Integer);
     procedure SetDefaultGroup(AValue: integer);
     procedure SetCacheCount(pNewCount: Integer);
+    procedure SetFoldColorInfosCount(pNewCount: Integer);
     procedure InitCache;
     procedure ClearCache;
     property FirstCharacterColumn[index: Integer]: Byte read GetFirstCharacterColumn;
@@ -150,6 +152,7 @@
   FDefaultGroup := 0;
   FFoldColorInfosCount := 0;
   SetLength(FFoldColorInfos, 50);
+  FFoldColorInfosCapacity := 50;
 
   FNestList := TLazSynEditNestedFoldsList.Create(Lines, FHighlighter);
   FNestList.ResetFilter;
@@ -298,7 +301,7 @@
         DebugLn('!!! TSynEditMarkupFoldColors.DoMarkupParentFoldAtRow: FEndLine-Array too small !!!');
       end;
     end;
-    inc(FFoldColorInfosCount);
+    SetFoldColorInfosCount(FFoldColorInfosCount + 1);
     with FFoldColorInfos[FFoldColorInfosCount - 1] do begin
 
       SrcNode:= ANode; //needed by close node
@@ -403,7 +406,7 @@
        FFoldColorInfos[j].Border := False
       end;
 
-    inc(FFoldColorInfosCount);
+    SetFoldColorInfosCount(FFoldColorInfosCount + 1);
     with FFoldColorInfos[FFoldColorInfosCount - 1] do begin
       Border := False;
       SrcNode:= ANode; //needed by close node
@@ -604,6 +607,18 @@
   FCacheCount := pNewCount;
 end;
 
+procedure TSynEditMarkupFoldColors.SetFoldColorInfosCount(pNewCount: Integer);
+var
+  i: Integer;
+begin
+  if pNewCount > FFoldColorInfosCapacity then begin
+    // expand array
+    FFoldColorInfosCapacity := pNewCount + 49;
+    SetLength(FFoldColorInfos, FFoldColorInfosCapacity);
+  end;
+  FFoldColorInfosCount := pNewCount;
+end;
+
 procedure TSynEditMarkupFoldColors.InitCache;
 begin
   if Assigned(FNestList) then

Martin Friebe

2017-01-24 02:30

manager   ~0097651

applied in 53987

Issue History

Date Modified Username Field Change
2016-12-01 22:29 Pascal Riekenberg New Issue
2016-12-01 22:29 Pascal Riekenberg File Added: syneditmarkupfoldcoloring.pas.patch
2017-01-24 02:30 Martin Friebe Fixed in Revision => 53987
2017-01-24 02:30 Martin Friebe LazTarget => 1.8
2017-01-24 02:30 Martin Friebe Note Added: 0097651
2017-01-24 02:30 Martin Friebe Status new => resolved
2017-01-24 02:30 Martin Friebe Fixed in Version => 1.8
2017-01-24 02:30 Martin Friebe Resolution open => fixed
2017-01-24 02:30 Martin Friebe Assigned To => Martin Friebe
2017-01-24 02:30 Martin Friebe Target Version => 1.8
2017-01-24 06:14 Pascal Riekenberg Status resolved => closed