mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 17:39:20 +02:00
rtl, utils: apply patch from Inoussa (mantis #24158):
* Fix the crash of the Unicode Manager and "cldrparser". Tested on WinCE/ARM emulator (That does produce unaliged exception). git-svn-id: trunk@25208 -
This commit is contained in:
parent
fb8fb29574
commit
24f8623490
@ -1199,12 +1199,14 @@ function TUCA_PropItemRec.GetCodePoint() : UInt24;
|
|||||||
begin
|
begin
|
||||||
if HasCodePoint() then begin
|
if HasCodePoint() then begin
|
||||||
if Contextual then
|
if Contextual then
|
||||||
Result := PUInt24(
|
Result := Unaligned(
|
||||||
PtrUInt(@Self) + Self.GetSelfOnlySize()- SizeOf(UInt24) -
|
PUInt24(
|
||||||
Cardinal(GetContext()^.Size)
|
PtrUInt(@Self) + Self.GetSelfOnlySize()- SizeOf(UInt24) -
|
||||||
)^
|
Cardinal(GetContext()^.Size)
|
||||||
|
)^
|
||||||
|
)
|
||||||
else
|
else
|
||||||
Result := PUInt24(PtrUInt(@Self) + Self.GetSelfOnlySize() - SizeOf(UInt24))^
|
Result := Unaligned(PUInt24(PtrUInt(@Self) + Self.GetSelfOnlySize() - SizeOf(UInt24))^)
|
||||||
end else begin
|
end else begin
|
||||||
{$ifdef uni_debug}
|
{$ifdef uni_debug}
|
||||||
raise EUnicodeException.Create('TUCA_PropItemRec.GetCodePoint : "No code point available."');
|
raise EUnicodeException.Create('TUCA_PropItemRec.GetCodePoint : "No code point available."');
|
||||||
@ -1238,17 +1240,17 @@ begin
|
|||||||
c := WeightLength;
|
c := WeightLength;
|
||||||
p := PByte(PtrUInt(@Self) + SizeOf(TUCA_PropItemRec));
|
p := PByte(PtrUInt(@Self) + SizeOf(TUCA_PropItemRec));
|
||||||
pd := ADest;
|
pd := ADest;
|
||||||
pd^.Weights[0] := PWord(p)^;
|
pd^.Weights[0] := Unaligned(PWord(p)^);
|
||||||
p := p + 2;
|
p := p + 2;
|
||||||
if not IsWeightCompress_1() then begin
|
if not IsWeightCompress_1() then begin
|
||||||
pd^.Weights[1] := PWord(p)^;
|
pd^.Weights[1] := Unaligned(PWord(p)^);
|
||||||
p := p + 2;
|
p := p + 2;
|
||||||
end else begin
|
end else begin
|
||||||
pd^.Weights[1] := p^;
|
pd^.Weights[1] := p^;
|
||||||
p := p + 1;
|
p := p + 1;
|
||||||
end;
|
end;
|
||||||
if not IsWeightCompress_2() then begin
|
if not IsWeightCompress_2() then begin
|
||||||
pd^.Weights[2] := PWord(p)^;
|
pd^.Weights[2] := Unaligned(PWord(p)^);
|
||||||
p := p + 2;
|
p := p + 2;
|
||||||
end else begin
|
end else begin
|
||||||
pd^.Weights[2] := p^;
|
pd^.Weights[2] := p^;
|
||||||
|
@ -28,6 +28,13 @@ unit cldrhelper;
|
|||||||
{$scopedenums on}
|
{$scopedenums on}
|
||||||
{$typedaddress on}
|
{$typedaddress on}
|
||||||
|
|
||||||
|
{$macro on}
|
||||||
|
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
|
||||||
|
{$define X_PACKED:=}
|
||||||
|
{$else FPC_REQUIRES_PROPER_ALIGNMENT}
|
||||||
|
{$define X_PACKED:=packed}
|
||||||
|
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -64,7 +71,7 @@ type
|
|||||||
|
|
||||||
{ TReorderUnit }
|
{ TReorderUnit }
|
||||||
|
|
||||||
TReorderUnit = packed record
|
TReorderUnit = X_PACKED record
|
||||||
public
|
public
|
||||||
Context : TUnicodeCodePointArray;
|
Context : TUnicodeCodePointArray;
|
||||||
ExpansionChars : TUnicodeCodePointArray;
|
ExpansionChars : TUnicodeCodePointArray;
|
||||||
@ -107,7 +114,7 @@ type
|
|||||||
|
|
||||||
{ TReorderSequence }
|
{ TReorderSequence }
|
||||||
|
|
||||||
TReorderSequence = packed record
|
TReorderSequence = X_PACKED record
|
||||||
public
|
public
|
||||||
Reset : array of TUnicodeCodePoint;
|
Reset : array of TUnicodeCodePoint;
|
||||||
Elements : array of TReorderUnit;
|
Elements : array of TReorderUnit;
|
||||||
|
@ -26,6 +26,13 @@ unit helper;
|
|||||||
{$typedaddress on}
|
{$typedaddress on}
|
||||||
{$warn 4056 off} //Conversion between ordinals and pointers is not portable
|
{$warn 4056 off} //Conversion between ordinals and pointers is not portable
|
||||||
|
|
||||||
|
{$macro on}
|
||||||
|
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
|
||||||
|
{$define X_PACKED:=}
|
||||||
|
{$else FPC_REQUIRES_PROPER_ALIGNMENT}
|
||||||
|
{$define X_PACKED:=packed}
|
||||||
|
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -197,7 +204,7 @@ type
|
|||||||
StartPosition : Word;
|
StartPosition : Word;
|
||||||
Length : Byte;
|
Length : Byte;
|
||||||
end;
|
end;
|
||||||
TDecompositionBook = packed record
|
TDecompositionBook = X_PACKED record
|
||||||
Index : array of TDecompositionIndexRec;
|
Index : array of TDecompositionIndexRec;
|
||||||
CodePoints : array of TUnicodeCodePoint;
|
CodePoints : array of TUnicodeCodePoint;
|
||||||
end;
|
end;
|
||||||
@ -230,7 +237,7 @@ type
|
|||||||
end;
|
end;
|
||||||
TUCA_WeightRecArray = array of TUCA_WeightRec;
|
TUCA_WeightRecArray = array of TUCA_WeightRec;
|
||||||
|
|
||||||
TUCA_LineContextItemRec = packed record
|
TUCA_LineContextItemRec = X_PACKED record
|
||||||
public
|
public
|
||||||
CodePoints : TUnicodeCodePointArray;
|
CodePoints : TUnicodeCodePointArray;
|
||||||
Weights : TUCA_WeightRecArray;
|
Weights : TUCA_WeightRecArray;
|
||||||
@ -241,7 +248,7 @@ type
|
|||||||
end;
|
end;
|
||||||
PUCA_LineContextItemRec = ^TUCA_LineContextItemRec;
|
PUCA_LineContextItemRec = ^TUCA_LineContextItemRec;
|
||||||
|
|
||||||
TUCA_LineContextRec = packed record
|
TUCA_LineContextRec = X_PACKED record
|
||||||
public
|
public
|
||||||
Data : array of TUCA_LineContextItemRec;
|
Data : array of TUCA_LineContextItemRec;
|
||||||
public
|
public
|
||||||
@ -253,7 +260,7 @@ type
|
|||||||
|
|
||||||
{ TUCA_LineRec }
|
{ TUCA_LineRec }
|
||||||
|
|
||||||
TUCA_LineRec = packed record
|
TUCA_LineRec = X_PACKED record
|
||||||
public
|
public
|
||||||
CodePoints : TUnicodeCodePointArray;
|
CodePoints : TUnicodeCodePointArray;
|
||||||
Weights : TUCA_WeightRecArray;
|
Weights : TUCA_WeightRecArray;
|
||||||
@ -272,7 +279,7 @@ type
|
|||||||
ucaShifted, ucaNonIgnorable, ucaBlanked, ucaShiftedTrimmed,
|
ucaShifted, ucaNonIgnorable, ucaBlanked, ucaShiftedTrimmed,
|
||||||
ucaIgnoreSP
|
ucaIgnoreSP
|
||||||
);
|
);
|
||||||
TUCA_DataBook = packed record
|
TUCA_DataBook = X_PACKED record
|
||||||
Version : string;
|
Version : string;
|
||||||
VariableWeight : TUCA_VariableKind;
|
VariableWeight : TUCA_VariableKind;
|
||||||
Backwards : array[0..3] of Boolean;
|
Backwards : array[0..3] of Boolean;
|
||||||
@ -352,7 +359,7 @@ type
|
|||||||
Position : Integer;
|
Position : Integer;
|
||||||
end;
|
end;
|
||||||
PUCA_PropIndexItem = ^TUCA_PropIndexItem;
|
PUCA_PropIndexItem = ^TUCA_PropIndexItem;
|
||||||
TUCA_PropBook = packed record
|
TUCA_PropBook = X_PACKED record
|
||||||
ItemSize : Integer;
|
ItemSize : Integer;
|
||||||
Index : array of TUCA_PropIndexItem;
|
Index : array of TUCA_PropIndexItem;
|
||||||
Items : PUCA_PropItemRec; //Native Endian
|
Items : PUCA_PropItemRec; //Native Endian
|
||||||
@ -2689,10 +2696,10 @@ begin
|
|||||||
end else begin
|
end else begin
|
||||||
Result := SizeOf(TUCA_PropItemRec) + (wl*SizeOf(TUCA_PropWeights));
|
Result := SizeOf(TUCA_PropItemRec) + (wl*SizeOf(TUCA_PropWeights));
|
||||||
pb := PByte(PtrUInt(p) + SizeOf(TUCA_PropItemRec));
|
pb := PByte(PtrUInt(p) + SizeOf(TUCA_PropItemRec));
|
||||||
PWord(pb)^ := AWeights[0].Weights[0];
|
Unaligned(PWord(pb)^) := AWeights[0].Weights[0];
|
||||||
pb := pb + 2;
|
pb := pb + 2;
|
||||||
if (AWeights[0].Weights[1] > High(Byte)) then begin
|
if (AWeights[0].Weights[1] > High(Byte)) then begin
|
||||||
PWord(pb)^ := AWeights[0].Weights[1];
|
Unaligned(PWord(pb)^) := AWeights[0].Weights[1];
|
||||||
pb := pb + 2;
|
pb := pb + 2;
|
||||||
end else begin
|
end else begin
|
||||||
SetBit(p^.Flags,p^.FLAG_COMPRESS_WEIGHT_1,True);
|
SetBit(p^.Flags,p^.FLAG_COMPRESS_WEIGHT_1,True);
|
||||||
@ -2701,7 +2708,7 @@ begin
|
|||||||
Result := Result - 1;
|
Result := Result - 1;
|
||||||
end;
|
end;
|
||||||
if (AWeights[0].Weights[2] > High(Byte)) then begin
|
if (AWeights[0].Weights[2] > High(Byte)) then begin
|
||||||
PWord(pb)^ := AWeights[0].Weights[2];
|
Unaligned(PWord(pb)^) := AWeights[0].Weights[2];
|
||||||
pb := pb + 2;
|
pb := pb + 2;
|
||||||
end else begin
|
end else begin
|
||||||
SetBit(p^.Flags,p^.FLAG_COMPRESS_WEIGHT_2,True);
|
SetBit(p^.Flags,p^.FLAG_COMPRESS_WEIGHT_2,True);
|
||||||
@ -2720,12 +2727,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
hasContext := (AContext <> nil) and (Length(AContext^.Data) > 0);
|
hasContext := (AContext <> nil) and (Length(AContext^.Data) > 0);
|
||||||
if AStoreCP or hasContext then begin
|
if AStoreCP or hasContext then begin
|
||||||
PUInt24(PtrUInt(AItem)+Result)^ := ACodePoint;
|
Unaligned(PUInt24(PtrUInt(AItem)+Result)^) := ACodePoint;
|
||||||
Result := Result + SizeOf(UInt24);
|
Result := Result + SizeOf(UInt24);
|
||||||
SetBit(AItem^.Flags,AItem^.FLAG_CODEPOINT,True);
|
SetBit(AItem^.Flags,AItem^.FLAG_CODEPOINT,True);
|
||||||
end;
|
end;
|
||||||
if hasContext then begin
|
if hasContext then begin
|
||||||
contextTree := ConstructContextTree(AContext,Pointer(PtrUInt(AItem)+Result)^,MaxInt);
|
contextTree := ConstructContextTree(AContext,Unaligned(Pointer(PtrUInt(AItem)+Result)^),MaxInt);
|
||||||
Result := Result + Cardinal(contextTree^.Size);
|
Result := Result + Cardinal(contextTree^.Size);
|
||||||
SetBit(AItem^.Flags,AItem^.FLAG_CONTEXTUAL,True);
|
SetBit(AItem^.Flags,AItem^.FLAG_CONTEXTUAL,True);
|
||||||
end;
|
end;
|
||||||
@ -4219,7 +4226,7 @@ begin
|
|||||||
k := s^.GetSelfOnlySize() - SizeOf(UInt24);
|
k := s^.GetSelfOnlySize() - SizeOf(UInt24);
|
||||||
p_s := PByte(PtrUInt(s) + k);
|
p_s := PByte(PtrUInt(s) + k);
|
||||||
p_d := PByte(PtrUInt(d) + k);
|
p_d := PByte(PtrUInt(d) + k);
|
||||||
PUInt24(p_d)^ := PUInt24(p_s)^;
|
Unaligned(PUInt24(p_d)^) := Unaligned(PUInt24(p_s)^);
|
||||||
ReverseBytes(p_d^,SizeOf(UInt24));
|
ReverseBytes(p_d^,SizeOf(UInt24));
|
||||||
end;
|
end;
|
||||||
if (s^.WeightLength > 0) then begin
|
if (s^.WeightLength > 0) then begin
|
||||||
@ -4227,8 +4234,8 @@ begin
|
|||||||
p_s := PByte(PtrUInt(s) + k);
|
p_s := PByte(PtrUInt(s) + k);
|
||||||
p_d := PByte(PtrUInt(d) + k);
|
p_d := PByte(PtrUInt(d) + k);
|
||||||
k := SizeOf(Word);
|
k := SizeOf(Word);
|
||||||
PWord(p_d)^ := PWord(p_s)^;
|
Unaligned(PWord(p_d)^) := Unaligned(PWord(p_s)^);
|
||||||
ReverseBytes(p_d^,k);
|
ReverseBytes(Unaligned(p_d^),k);
|
||||||
p_s := PByte(PtrUInt(p_s) + k);
|
p_s := PByte(PtrUInt(p_s) + k);
|
||||||
p_d := PByte(PtrUInt(p_d) + k);
|
p_d := PByte(PtrUInt(p_d) + k);
|
||||||
if s^.IsWeightCompress_1() then begin
|
if s^.IsWeightCompress_1() then begin
|
||||||
@ -4236,7 +4243,7 @@ begin
|
|||||||
PByte(p_d)^ := PByte(p_s)^;
|
PByte(p_d)^ := PByte(p_s)^;
|
||||||
end else begin
|
end else begin
|
||||||
k := SizeOf(Word);
|
k := SizeOf(Word);
|
||||||
PWord(p_d)^ := PWord(p_s)^;
|
Unaligned(PWord(p_d)^) := Unaligned(PWord(p_s)^);
|
||||||
end;
|
end;
|
||||||
ReverseBytes(p_d^,k);
|
ReverseBytes(p_d^,k);
|
||||||
p_s := PByte(PtrUInt(p_s) + k);
|
p_s := PByte(PtrUInt(p_s) + k);
|
||||||
@ -4246,7 +4253,7 @@ begin
|
|||||||
PByte(p_d)^ := PByte(p_s)^;
|
PByte(p_d)^ := PByte(p_s)^;
|
||||||
end else begin
|
end else begin
|
||||||
k := SizeOf(Word);
|
k := SizeOf(Word);
|
||||||
PWord(p_d)^ := PWord(p_s)^;
|
Unaligned(PWord(p_d)^) := Unaligned(PWord(p_s)^);
|
||||||
end;
|
end;
|
||||||
ReverseBytes(p_d^,k);
|
ReverseBytes(p_d^,k);
|
||||||
if (s^.WeightLength > 1) then begin
|
if (s^.WeightLength > 1) then begin
|
||||||
@ -4365,7 +4372,7 @@ begin
|
|||||||
k := d^.GetSelfOnlySize() - SizeOf(UInt24);
|
k := d^.GetSelfOnlySize() - SizeOf(UInt24);
|
||||||
p_s := PByte(PtrUInt(s) + k);
|
p_s := PByte(PtrUInt(s) + k);
|
||||||
p_d := PByte(PtrUInt(d) + k);
|
p_d := PByte(PtrUInt(d) + k);
|
||||||
PUInt24(p_d)^ := PUInt24(p_s)^;
|
Unaligned(PUInt24(p_d)^) := Unaligned(PUInt24(p_s)^);
|
||||||
ReverseBytes(p_d^,SizeOf(UInt24));
|
ReverseBytes(p_d^,SizeOf(UInt24));
|
||||||
end;
|
end;
|
||||||
if (d^.WeightLength > 0) then begin
|
if (d^.WeightLength > 0) then begin
|
||||||
@ -4373,7 +4380,7 @@ begin
|
|||||||
p_s := PByte(PtrUInt(s) + k);
|
p_s := PByte(PtrUInt(s) + k);
|
||||||
p_d := PByte(PtrUInt(d) + k);
|
p_d := PByte(PtrUInt(d) + k);
|
||||||
k := SizeOf(Word);
|
k := SizeOf(Word);
|
||||||
PWord(p_d)^ := PWord(p_s)^;
|
Unaligned(PWord(p_d)^) := Unaligned(PWord(p_s)^);
|
||||||
ReverseBytes(p_d^,k);
|
ReverseBytes(p_d^,k);
|
||||||
p_s := PByte(PtrUInt(p_s) + k);
|
p_s := PByte(PtrUInt(p_s) + k);
|
||||||
p_d := PByte(PtrUInt(p_d) + k);
|
p_d := PByte(PtrUInt(p_d) + k);
|
||||||
@ -4382,7 +4389,7 @@ begin
|
|||||||
PByte(p_d)^ := PByte(p_s)^;
|
PByte(p_d)^ := PByte(p_s)^;
|
||||||
end else begin
|
end else begin
|
||||||
k := SizeOf(Word);
|
k := SizeOf(Word);
|
||||||
PWord(p_d)^ := PWord(p_s)^;
|
Unaligned(PWord(p_d)^) := Unaligned(PWord(p_s)^);
|
||||||
end;
|
end;
|
||||||
ReverseBytes(p_d^,k);
|
ReverseBytes(p_d^,k);
|
||||||
p_s := PByte(PtrUInt(p_s) + k);
|
p_s := PByte(PtrUInt(p_s) + k);
|
||||||
@ -4392,7 +4399,7 @@ begin
|
|||||||
PByte(p_d)^ := PByte(p_s)^;
|
PByte(p_d)^ := PByte(p_s)^;
|
||||||
end else begin
|
end else begin
|
||||||
k := SizeOf(Word);
|
k := SizeOf(Word);
|
||||||
PWord(p_d)^ := PWord(p_s)^;
|
Unaligned(PWord(p_d)^) := Unaligned(PWord(p_s)^);
|
||||||
end;
|
end;
|
||||||
ReverseBytes(p_d^,k);
|
ReverseBytes(p_d^,k);
|
||||||
if (d^.WeightLength > 1) then begin
|
if (d^.WeightLength > 1) then begin
|
||||||
|
Loading…
Reference in New Issue
Block a user