Browse Source

fixed unaligned memory access on Delphi ARM devices

Ugochukwu Mmaduekwe 6 years ago
parent
commit
b47eae7518
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/libraries/hashlib4pascal/HlpConverters.pas

+ 10 - 0
src/libraries/hashlib4pascal/HlpConverters.pas

@@ -265,22 +265,32 @@ end;
 class function TConverters.ReadBytesAsUInt32LE(a_in: PByte;
   a_index: Int32): UInt32;
 begin
+{$IFDEF FPC}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
   System.Move(a_in[a_index], result, System.SizeOf(UInt32));
 {$ELSE}
   result := PCardinal(a_in + a_index)^;
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
+{$ELSE}
+  // Delphi does not handle unaligned memory access on ARM Devices properly.
+  System.Move(a_in[a_index], result, System.SizeOf(UInt32));
+{$ENDIF FPC}
   result := le2me_32(result);
 end;
 
 class function TConverters.ReadBytesAsUInt64LE(a_in: PByte;
   a_index: Int32): UInt64;
 begin
+{$IFDEF FPC}
 {$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
   System.Move(a_in[a_index], result, System.SizeOf(UInt64));
 {$ELSE}
   result := PUInt64(a_in + a_index)^;
 {$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
+{$ELSE}
+  // Delphi does not handle unaligned memory access on ARM Devices properly.
+  System.Move(a_in[a_index], result, System.SizeOf(UInt64));
+{$ENDIF FPC}
   result := le2me_64(result);
 end;