Skip to content

Commit d320404

Browse files
committed
Issue #1260: Use new type TNodeHeight in more places to avoid integer overflow.
1 parent 83ab625 commit d320404

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

Source/VirtualTrees.BaseTree.pas

+17-15
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ TVirtualTreeClass = class of TBaseVirtualTree;
120120
// to compile (conversion done by BCB is wrong).
121121
TCacheEntry = record
122122
Node: PVirtualNode;
123-
AbsoluteTop: TDimension;
123+
AbsoluteTop: TNodeHeight;
124124
end;
125125

126126
TCache = array of TCacheEntry;
@@ -531,7 +531,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
531531
FOffsetY: TDimension; // Determines left and top scroll offset.
532532
FEffectiveOffsetX: TDimension; // Actual position of the horizontal scroll bar (varies depending on bidi mode).
533533
FRangeX,
534-
FRangeY: TDimension; // current virtual width and height of the tree
534+
FRangeY: TNodeHeight; // current virtual width and height of the tree
535535
FBottomSpace: TDimension; // Extra space below the last node.
536536

537537
FDefaultPasteMode: TVTNodeAttachMode; // Used to determine where to add pasted nodes to.
@@ -739,8 +739,8 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
739739
procedure ClearNodeBackground(const PaintInfo: TVTPaintInfo; UseBackground, Floating: Boolean; R: TRect);
740740
function CompareNodePositions(Node1, Node2: PVirtualNode; ConsiderChildrenAbove: Boolean = False): Integer;
741741
procedure DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, VAlign: TDimension; Style: TVTLineType; Reverse: Boolean);
742-
function FindInPositionCache(Node: PVirtualNode; var CurrentPos: TDimension): PVirtualNode; overload;
743-
function FindInPositionCache(Position: TDimension; var CurrentPos: TDimension): PVirtualNode; overload;
742+
function FindInPositionCache(Node: PVirtualNode; var CurrentPos: TNodeHeight): PVirtualNode; overload;
743+
function FindInPositionCache(Position: TDimension; var CurrentPos: TNodeHeight): PVirtualNode; overload;
744744
procedure FixupTotalCount(Node: PVirtualNode);
745745
procedure FixupTotalHeight(Node: PVirtualNode);
746746
function GetBottomNode: PVirtualNode;
@@ -904,7 +904,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
904904
procedure AddToSelection(const NewItems: TNodeArray; NewLength: Integer; ForceInsert: Boolean = False); overload; virtual;
905905
procedure AdjustPaintCellRect(var PaintInfo: TVTPaintInfo; var NextNonEmpty: TColumnIndex); virtual;
906906
procedure AdjustPanningCursor(X, Y: TDimension); virtual;
907-
procedure AdjustTotalHeight(Node: PVirtualNode; Value: TDimension; relative: Boolean = False);
907+
procedure AdjustTotalHeight(Node: PVirtualNode; Value: TNodeHeight; relative: Boolean = False);
908908
procedure AdviseChangeEvent(StructureChange: Boolean; Node: PVirtualNode; Reason: TChangeReason); virtual;
909909
function AllocateInternalDataArea(Size: Cardinal): Cardinal; virtual;
910910
procedure Animate(Steps, Duration: Cardinal; Callback: TVTAnimationCallback; Data: Pointer); virtual;
@@ -1235,7 +1235,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
12351235
property MinusBM: TBitmap read FMinusBM;
12361236
property PlusBM: TBitmap read FPlusBM;
12371237
property RangeX: TDimension read GetRangeX;// Returns the width of the virtual tree in pixels, (not ClientWidth). If there are columns it returns the total width of all of them; otherwise it returns the maximum of the all the line's data widths.
1238-
property RangeY: TDimension read FRangeY;
1238+
property RangeY: TNodeHeight read FRangeY;
12391239
property RootNodeCount: Cardinal read GetRootNodeCount write SetRootNodeCount default 0;
12401240
property ScrollBarOptions: TScrollBarOptions read FScrollBarOptions write SetScrollBarOptions;
12411241
property SelectionBlendFactor: Byte read FSelectionBlendFactor write FSelectionBlendFactor default 128;
@@ -2211,12 +2211,12 @@ procedure TBaseVirtualTree.AdjustTotalCount(Node: PVirtualNode; Value: Integer;
22112211

22122212
//----------------------------------------------------------------------------------------------------------------------
22132213

2214-
procedure TBaseVirtualTree.AdjustTotalHeight(Node: PVirtualNode; Value: TDimension; Relative: Boolean = False);
2214+
procedure TBaseVirtualTree.AdjustTotalHeight(Node: PVirtualNode; Value: TNodeHeight; Relative: Boolean = False);
22152215

22162216
// Sets a node's total height to the given value and recursively adjusts the parent's total height.
22172217

22182218
var
2219-
Difference: TDimension;
2219+
Difference: TNodeHeight;
22202220
Run: PVirtualNode;
22212221

22222222
begin
@@ -2997,7 +2997,7 @@ procedure TBaseVirtualTree.DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H,
29972997

29982998
//----------------------------------------------------------------------------------------------------------------------
29992999

3000-
function TBaseVirtualTree.FindInPositionCache(Node: PVirtualNode; var CurrentPos: TDimension): PVirtualNode;
3000+
function TBaseVirtualTree.FindInPositionCache(Node: PVirtualNode; var CurrentPos: TNodeHeight): PVirtualNode;
30013001

30023002
// Looks through the position cache and returns the node whose top position is the largest one which is smaller or equal
30033003
// to the position of the given node.
@@ -3030,7 +3030,7 @@ function TBaseVirtualTree.FindInPositionCache(Node: PVirtualNode; var CurrentPos
30303030

30313031
//----------------------------------------------------------------------------------------------------------------------
30323032

3033-
function TBaseVirtualTree.FindInPositionCache(Position: TDimension; var CurrentPos: TDimension): PVirtualNode;
3033+
function TBaseVirtualTree.FindInPositionCache(Position: TDimension; var CurrentPos: TNodeHeight): PVirtualNode;
30343034

30353035
// Looks through the position cache and returns the node whose top position is the largest one which is smaller or equal
30363036
// to the given vertical position.
@@ -9328,7 +9328,9 @@ function TBaseVirtualTree.DetermineScrollDirections(X, Y: TDimension): TScrollDi
93289328
// yet elapsed.
93299329
if ((Int64(timeGetTime) - FDragScrollStart) < FAutoScrollDelay) then
93309330
Result := [];
9331-
end;
9331+
end
9332+
else
9333+
OutputDebugString('Ooops');
93329334
end;
93339335
end;
93349336
end;
@@ -11029,7 +11031,7 @@ function TBaseVirtualTree.DoValidateCache(): Boolean;
1102911031
Index: Cardinal;
1103011032
CurrentNode,
1103111033
Temp: PVirtualNode;
11032-
CurrentTop: TDimension;
11034+
CurrentTop: TNodeHeight;
1103311035
begin
1103411036
EntryCount := 0;
1103511037
if not (tsStopValidation in FStates) then
@@ -16851,7 +16853,7 @@ function TBaseVirtualTree.GetDisplayRect(Node: PVirtualNode; Column: TColumnInde
1685116853
var
1685216854
Temp: PVirtualNode;
1685316855
LeftOffset: TDimension;
16854-
TopOffset: TDimension;
16856+
TopOffset: TNodeHeight;
1685516857
CacheIsAvailable: Boolean;
1685616858
TextWidth: TDimension;
1685716859
CurrentBidiMode: TBidiMode;
@@ -18463,7 +18465,7 @@ function TBaseVirtualTree.GetNodeAt(X, Y: TDimension; Relative: Boolean; var Nod
1846318465

1846418466
var
1846518467
AbsolutePos,
18466-
CurrentPos: TDimension;
18468+
CurrentPos: TNodeHeight;
1846718469

1846818470
begin
1846918471
if Y < 0 then
@@ -22616,7 +22618,7 @@ procedure TBaseVirtualTree.UpdateVerticalRange;
2261622618
DoShowScrollBar(SB_VERT, True);
2261722619

2261822620
ScrollInfo.nMin := 0;
22619-
ScrollInfo.nMax := FRangeY;
22621+
ScrollInfo.nMax := IfThen(FRangeY < MaxInt, FRangeY, MaxInt); // TScrollInfo values are signed 32bit only
2262022622
ScrollInfo.nPos := -FOffsetY;
2262122623
ScrollInfo.nPage := Max(0, ClientHeight + 1);
2262222624

0 commit comments

Comments
 (0)