LCL: Consider that MemSize can return 0 with a custom MemoryManager. Merge request !27 by Sergey Larin.

This commit is contained in:
Juha 2021-10-28 11:18:14 +03:00
parent 8af9cd0918
commit 75aebbee85
11 changed files with 24 additions and 17 deletions

View File

@ -1553,11 +1553,11 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrUInt(SizeOf(TTriVertex) * NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrUInt(SizeOf(TTriVertex) * NumVertices)) then
Exit;
//Sanity Checks For Meshes Size vs. Count
if MemSize(Meshes) < (MeshSize[DoFillTriangle] * Cardinal(NumMeshes)) then
if MemSizeLessThan(MemSize(Meshes), (MeshSize[DoFillTriangle] * Cardinal(NumMeshes))) then
Exit;
for I := 0 to NumMeshes - 1 do

View File

@ -176,6 +176,8 @@ type
function GetDefaultLCLWidgetType: TLCLPlatform;
function GetLCLWidgetTypeName: string;
function MemSizeLessThan(AMemSize, AThen: PtrUInt): Boolean; inline;
const
{ Constants for the routine TWidgetSet.GetLCLCapability }
LCL_CAPABILITY_NO = 0;
@ -233,6 +235,11 @@ begin
Result:=LCLPlatformDirNames[GetDefaultLCLWidgetType];
end;
function MemSizeLessThan(AMemSize, AThen: PtrUInt): Boolean; inline;
begin
Result:=(AMemSize<>0) and (AMemSize<AThen);
end;
{ TDialogButtons }
procedure TDialogButtons.SetCancelButton(const AValue: TDialogButton);

View File

@ -2477,7 +2477,7 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
for I := 0 to NumMeshes - 1 do

View File

@ -4468,11 +4468,11 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
//Sanity Checks For Meshes Size vs. Count
if MemSize(Meshes) < PtrUInt(MeshSize[DoFillTriangle]*NumMeshes) then
if MemSizeLessThan(MemSize(Meshes), PtrUInt(MeshSize[DoFillTriangle]*NumMeshes)) then
exit;
for I := 0 to NumMeshes - 1 do

View File

@ -4544,11 +4544,11 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
//Sanity Checks For Meshes Size vs. Count
if MemSize(Meshes) < PtrUInt(MeshSize[DoFillTriangle]*NumMeshes) then
if MemSizeLessThan(MemSize(Meshes), PtrUInt(MeshSize[DoFillTriangle]*NumMeshes)) then
exit;
for I := 0 to NumMeshes - 1 do

View File

@ -4528,11 +4528,11 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
//Sanity Checks For Meshes Size vs. Count
if MemSize(Meshes) < PtrUInt(MeshSize[DoFillTriangle]*NumMeshes) then
if MemSizeLessThan(MemSize(Meshes), PtrUInt(MeshSize[DoFillTriangle]*NumMeshes)) then
exit;
for I := 0 to NumMeshes - 1 do

View File

@ -1763,7 +1763,7 @@ begin
BitSize := longint(SizeOf(Byte))
*(longint(biSizeImage) div biHeight)
*longint(NumScans + StartScan);
if MemSize(Bits) < PtrInt(BitSize)
if MemSizeLessThan(MemSize(Bits), PtrInt(BitSize))
then begin
DebugLn('WARNING: [TGtkWidgetSet.InternalGetDIBits] not enough memory allocated for Bits!');
exit;

View File

@ -6676,11 +6676,11 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrInt(SizeOf(tagTRIVERTEX)*NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
//Sanity Checks For Meshes Size vs. Count
if MemSize(Meshes) < PtrInt(MeshSize[DoFillTriangle]*NumMeshes) then
if MemSizeLessThan(MemSize(Meshes), PtrInt(MeshSize[DoFillTriangle]*NumMeshes)) then
exit;
for I := 0 to NumMeshes - 1 do

View File

@ -2991,7 +2991,7 @@ begin
BitSize := longint(SizeOf(Byte))
*(longint(biSizeImage) div biHeight)
*longint(NumScans + StartScan);
if MemSize(Bits) < PtrInt(BitSize)
if MemSizeLessThan(MemSize(Bits), PtrInt(BitSize))
then begin
DebugLn('WARNING: [TGtk2WidgetSet.InternalGetDIBits] not enough memory allocated for Bits!');
exit;

View File

@ -4810,11 +4810,11 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
//Sanity Checks For Meshes Size vs. Count
if MemSize(Meshes) < PtrUInt(MeshSize[DoFillTriangle]*NumMeshes) then
if MemSizeLessThan(MemSize(Meshes), PtrUInt(MeshSize[DoFillTriangle]*NumMeshes)) then
exit;
for I := 0 to NumMeshes - 1 do

View File

@ -4752,11 +4752,11 @@ begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSize(Vertices) < PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices) then
if MemSizeLessThan(MemSize(Vertices), PtrUInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
//Sanity Checks For Meshes Size vs. Count
if MemSize(Meshes) < PtrUInt(MeshSize[DoFillTriangle]*NumMeshes) then
if MemSizeLessThan(MemSize(Meshes), PtrUInt(MeshSize[DoFillTriangle]*NumMeshes)) then
exit;
for I := 0 to NumMeshes - 1 do