* fix : ensure that the 8- and 16-bit signed overloads of IntToHex return the correct number of digits

+ added test

(cherry picked from commit d32134dd1a)
This commit is contained in:
Sven/Sarah Barth 2022-04-19 14:21:26 +02:00
parent 7c5a81abac
commit affd8b02d9
2 changed files with 45 additions and 2 deletions
rtl/objpas/sysutils
tests/webtbs

View File

@ -921,7 +921,7 @@ end;
function IntToHex(Value: Int8): string;
begin
Result:=IntToHex(Value, 2*SizeOf(Int8));
Result:=IntToHex(LongInt(Value) and $ff, 2*SizeOf(Int8));
end;
function IntToHex(Value: UInt8): string;
@ -931,7 +931,7 @@ end;
function IntToHex(Value: Int16): string;
begin
Result:=IntToHex(Value, 2*SizeOf(Int16));
Result:=IntToHex(LongInt(Value) and $ffff, 2*SizeOf(Int16));
end;
function IntToHex(Value: UInt16): string;

43
tests/webtbs/tw39664.pp Normal file
View File

@ -0,0 +1,43 @@
program tw39664;
{$mode Delphi}
uses
SysUtils;
var
i8: Int8;
i16: Int16;
i32: Int32;
u32: UInt32;
s: String;
begin
i8 := -42;
s := IntToHex(i8);
writeln(s);
if s <> 'D6' then halt(1);
i16 := -42;
s := IntToHex(i16);
writeln(s);
if s <> 'FFD6' then halt(2);
i32 := -42;
s := IntToHex(i32);
writeln(s);
if s <> 'FFFFFFD6' then halt(3);
s := i8.ToHexString;
writeln(s);
if s <> 'D6' then halt(4);
s := i16.ToHexString;
writeln(s);
if s <> 'FFD6' then halt(5);
s := i32.ToHexString;
writeln(s);
if s <> 'FFFFFFD6' then halt(6);
end.