* avoid range check error when using SwapEndian with 16-bit constants

+ added test

git-svn-id: trunk@46897 -
This commit is contained in:
svenbarth 2020-09-19 17:04:17 +00:00
parent 74a641344a
commit 9d86fed95b
5 changed files with 21 additions and 6 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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;
(*

View File

@ -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}

View File

@ -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
View 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.