Use a record of signed SmallInts to prevent range check errors. Still about issue #22760

git-svn-id: trunk@38476 -
This commit is contained in:
juha 2012-09-02 00:32:29 +00:00
parent b10c7aef8b
commit 995b5a3d55
6 changed files with 26 additions and 16 deletions

View File

@ -101,7 +101,7 @@ function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
var var
lft : TFileTime; lft : TFileTime;
begin begin
ADosTimeToWinTime:=DosDateTimeToFileTime(LongRec(DosTime).hi,LongRec(DosTime).lo,@lft) and ADosTimeToWinTime:=DosDateTimeToFileTime(longrec(DosTime).hi,longrec(DosTime).lo,@lft) and
LocalFileTimeToFileTime(lft,Wintime); LocalFileTimeToFileTime(lft,Wintime);
end; end;
var var

View File

@ -164,7 +164,7 @@ begin
LookupRoot.DesignInfo := LeftTopToDesignInfo(Left, Top); LookupRoot.DesignInfo := LeftTopToDesignInfo(Left, Top);
// always fill the whole designer form // always fill the whole designer form
TControl(LookupRoot).SetBounds(0, 0, Width, Height); TControl(LookupRoot).SetBounds(0, 0, Width, Height);
//DebugLn(['TFrameDesignerForm.DoSaveBounds ',Left,',',Top,' ',LongRec(LookupRoot.DesignInfo).Lo,',',LongRec(LookupRoot.DesignInfo).hi]); //DebugLn(['TFrameDesignerForm.DoSaveBounds ',Left,',',Top,' ',LazLongRec(LookupRoot.DesignInfo).Lo,',',LazLongRec(LookupRoot.DesignInfo).hi]);
end end
else else
if LookupRoot <> nil then if LookupRoot <> nil then

View File

@ -1298,7 +1298,7 @@ begin
// no parent and not a form // no parent and not a form
AControl.SetBounds(0,0,CompWidth,CompHeight); AControl.SetBounds(0,0,CompWidth,CompHeight);
AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop); AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop);
//DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]); //DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LazLongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]);
end; end;
end end
else else

View File

@ -23,7 +23,7 @@ interface
uses uses
Math, Classes, SysUtils, LCLProc, TypInfo, types, Forms, Controls, Math, Classes, SysUtils, LCLProc, TypInfo, types, Forms, Controls,
ProjectIntf, ComponentEditors, ObjectInspector; LCLClasses, ProjectIntf, ComponentEditors, ObjectInspector;
const const
ComponentPaletteImageWidth = 24; ComponentPaletteImageWidth = 24;
@ -241,24 +241,24 @@ end;
function LeftFromDesignInfo(ADesignInfo: LongInt): SmallInt; function LeftFromDesignInfo(ADesignInfo: LongInt): SmallInt;
begin begin
Result := SmallInt(LongRec(ADesignInfo).Lo); Result := LazLongRec(ADesignInfo).Lo;
end; end;
function TopFromDesignInfo(ADesignInfo: LongInt): SmallInt; function TopFromDesignInfo(ADesignInfo: LongInt): SmallInt;
begin begin
Result := SmallInt(LongRec(ADesignInfo).Hi); Result := LazLongRec(ADesignInfo).Hi;
end; end;
function LeftTopToDesignInfo(const ALeft, ATop: SmallInt): LongInt; function LeftTopToDesignInfo(const ALeft, ATop: SmallInt): LongInt;
begin begin
LongRec(Result).Lo:=Word(ALeft); LazLongRec(Result).Lo:=ALeft;
LongRec(Result).Hi:=Word(ATop); LazLongRec(Result).Hi:=ATop;
end; end;
procedure DesignInfoToLeftTop(ADesignInfo: LongInt; out ALeft, ATop: SmallInt); procedure DesignInfoToLeftTop(ADesignInfo: LongInt; out ALeft, ATop: SmallInt);
begin begin
ALeft := SmallInt(LongRec(ADesignInfo).Lo); ALeft := LazLongRec(ADesignInfo).Lo;
ATop := SmallInt(LongRec(ADesignInfo).Hi); ATop := LazLongRec(ADesignInfo).Hi;
end; end;
{ TDesignerMediator } { TDesignerMediator }

View File

@ -40,7 +40,7 @@ var
Temp: LongInt; Temp: LongInt;
begin begin
Temp:=DesignInfo; Temp:=DesignInfo;
LongRec(Temp).Lo:=Word(Reader.ReadInteger); LazLongRec(Temp).Lo:=Reader.ReadInteger;
DesignInfo:=Temp; DesignInfo:=Temp;
end; end;
@ -49,18 +49,18 @@ var
Temp: LongInt; Temp: LongInt;
begin begin
Temp:=DesignInfo; Temp:=DesignInfo;
LongRec(Temp).Hi:=Word(Reader.ReadInteger); LazLongRec(Temp).Hi:=Reader.ReadInteger;
DesignInfo:=Temp; DesignInfo:=Temp;
end; end;
procedure TCustomFrame.WriteDesignLeft(Writer: TWriter); procedure TCustomFrame.WriteDesignLeft(Writer: TWriter);
begin begin
Writer.WriteInteger(LongInt(LongRec(DesignInfo).Lo)); Writer.WriteInteger(LazLongRec(DesignInfo).Lo);
end; end;
procedure TCustomFrame.WriteDesignTop(Writer: TWriter); procedure TCustomFrame.WriteDesignTop(Writer: TWriter);
begin begin
Writer.WriteInteger(LongInt(LongRec(DesignInfo).Hi)); Writer.WriteInteger(LazLongRec(DesignInfo).Hi);
end; end;
class procedure TCustomFrame.WSRegisterClass; class procedure TCustomFrame.WSRegisterClass;
@ -148,9 +148,9 @@ begin
Ancestor:=TComponent(Filer.Ancestor); Ancestor:=TComponent(Filer.Ancestor);
if Assigned(Ancestor) then Temp:=Ancestor.DesignInfo; if Assigned(Ancestor) then Temp:=Ancestor.DesignInfo;
Filer.Defineproperty('DesignLeft',@ReadDesignLeft,@WriteDesignLeft, Filer.Defineproperty('DesignLeft',@ReadDesignLeft,@WriteDesignLeft,
(LongRec(DesignInfo).Lo<>LongRec(Temp).Lo)); (LazLongRec(DesignInfo).Lo<>LazLongrec(Temp).Lo));
Filer.Defineproperty('DesignTop',@ReadDesignTop,@WriteDesignTop, Filer.Defineproperty('DesignTop',@ReadDesignTop,@WriteDesignTop,
(LongRec(DesignInfo).Hi<>LongRec(Temp).Hi)); (LazLongRec(DesignInfo).Hi<>LazLongrec(Temp).Hi));
end; end;
procedure TCustomFrame.CalculatePreferredSize(var PreferredWidth, procedure TCustomFrame.CalculatePreferredSize(var PreferredWidth,

View File

@ -33,6 +33,16 @@ uses
type type
// SysUtils.LongRec has unsigned Word for Lo and Hi,
// we need a similar record with signed ShortInt
LazLongRec = packed record
{$ifdef FPC_LITTLE_ENDIAN}
Lo,Hi : SmallInt;
{$else FPC_LITTLE_ENDIAN}
Hi,Lo : SmallInt;
{$endif FPC_LITTLE_ENDIAN}
end;
{ TLCLComponent } { TLCLComponent }
TLCLComponent = class(TComponent) TLCLComponent = class(TComponent)