mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-24 00:59:07 +02:00
* avoid range check error when using SwapEndian with 16-bit constants
+ added test git-svn-id: trunk@46897 -
This commit is contained in:
parent
74a641344a
commit
9d86fed95b
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -13349,6 +13349,7 @@ tests/tbs/tb0672.pp svneol=native#text/pascal
|
||||
tests/tbs/tb0673.pp svneol=native#text/pascal
|
||||
tests/tbs/tb0674.pp svneol=native#text/pascal
|
||||
tests/tbs/tb0675.pp svneol=native#text/pascal
|
||||
tests/tbs/tb0676.pp svneol=native#text/pascal
|
||||
tests/tbs/ub0060.pp svneol=native#text/plain
|
||||
tests/tbs/ub0069.pp svneol=native#text/plain
|
||||
tests/tbs/ub0119.pp svneol=native#text/plain
|
||||
|
@ -1190,13 +1190,13 @@ function SwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inlin
|
||||
{ is turned into "longint(AValue) shr 8", so if AValue < 0 then }
|
||||
{ the sign bits from the upper 16 bits are shifted in rather than }
|
||||
{ zeroes. }
|
||||
Result := SmallInt((Word(AValue) shr 8) or (Word(AValue) shl 8));
|
||||
Result := ((Word(AValue) shr 8) or (Word(AValue) shl 8)) and $ffff;
|
||||
end;
|
||||
|
||||
|
||||
function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
|
||||
begin
|
||||
Result := Word((AValue shr 8) or (AValue shl 8));
|
||||
Result := ((AValue shr 8) or (AValue shl 8)) and $ffff;
|
||||
end;
|
||||
|
||||
(*
|
||||
|
@ -2663,13 +2663,13 @@ function SwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inlin
|
||||
{ is turned into "longint(AValue) shr 8", so if AValue < 0 then }
|
||||
{ the sign bits from the upper 16 bits are shifted in rather than }
|
||||
{ zeroes. }
|
||||
Result := SmallInt((Word(AValue) shr 8) or (Word(AValue) shl 8));
|
||||
Result := ((Word(AValue) shr 8) or (Word(AValue) shl 8)) and $ffff;
|
||||
end;
|
||||
|
||||
{$ifndef cpujvm}
|
||||
function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
|
||||
begin
|
||||
Result := Word((AValue shr 8) or (AValue shl 8));
|
||||
Result := ((AValue shr 8) or (AValue shl 8)) and $ffff;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
|
@ -1021,13 +1021,13 @@ function SwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inlin
|
||||
{ is turned into "longint(AValue) shr 8", so if AValue < 0 then }
|
||||
{ the sign bits from the upper 16 bits are shifted in rather than }
|
||||
{ zeroes. }
|
||||
Result := SmallInt((Word(AValue) shr 8) or (Word(AValue) shl 8));
|
||||
Result := ((Word(AValue) shr 8) or (Word(AValue) shl 8)) and $ffff;
|
||||
end;
|
||||
|
||||
|
||||
function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
|
||||
begin
|
||||
Result := Word((AValue shr 8) or (AValue shl 8));
|
||||
Result := ((AValue shr 8) or (AValue shl 8)) and $ffff;
|
||||
end;
|
||||
|
||||
|
||||
|
14
tests/tbs/tb0676.pp
Normal file
14
tests/tbs/tb0676.pp
Normal file
@ -0,0 +1,14 @@
|
||||
{ %NORUN }
|
||||
|
||||
program tb0676;
|
||||
|
||||
{$warn 4110 error}
|
||||
|
||||
begin
|
||||
SwapEndian(UInt16($1234));
|
||||
SwapEndian(Int16($8765));
|
||||
SwapEndian(UInt32($12345678));
|
||||
SwapEndian(Int32($87654321));
|
||||
SwapEndian(UInt64($1234567887654321));
|
||||
SwapEndian(Int64($8765432112345678));
|
||||
end.
|
Loading…
Reference in New Issue
Block a user