mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-07 21:49:27 +01:00
* new rangecheck code now handles conversion between signed and cardinal types correctly
This commit is contained in:
parent
02591a89d9
commit
2e3ba14936
@ -1156,9 +1156,37 @@ implementation
|
|||||||
|
|
||||||
{ is_signed now also works for arrays (it checks the rangetype) (JM) }
|
{ is_signed now also works for arrays (it checks the rangetype) (JM) }
|
||||||
if is_signed(fromdef) xor is_signed(todef) then
|
if is_signed(fromdef) xor is_signed(todef) then
|
||||||
|
if is_signed(fromdef) then
|
||||||
|
{ from is signed, to is unsigned }
|
||||||
begin
|
begin
|
||||||
lto := max(lto,0);
|
{ if high(from) < 0 -> always range error }
|
||||||
hto := hto and $7fffffff;
|
if (hfrom < 0) or
|
||||||
|
{ if low(to) > maxlongint (== < 0, since we only have }
|
||||||
|
{ longints here), also range error }
|
||||||
|
(lto < 0) then
|
||||||
|
begin
|
||||||
|
emitcall('FPC_RANGEERROR');
|
||||||
|
exit
|
||||||
|
end;
|
||||||
|
{ to is unsigned -> hto < 0 == hto > maxlongint }
|
||||||
|
{ since from is signed, values > maxlongint are < 0 and must }
|
||||||
|
{ be rejected }
|
||||||
|
if hto < 0 then
|
||||||
|
hto := maxlongint;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{ from is unsigned, to is signed }
|
||||||
|
begin
|
||||||
|
if (lfrom < 0) or
|
||||||
|
(hto < 0) then
|
||||||
|
begin
|
||||||
|
emitcall('FPC_RANGEERROR');
|
||||||
|
exit
|
||||||
|
end;
|
||||||
|
{ since from is unsigned, values > maxlongint are < 0 and must }
|
||||||
|
{ be rejected }
|
||||||
|
if lto < 0 then
|
||||||
|
lto := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if is_reg and
|
if is_reg and
|
||||||
@ -1454,7 +1482,10 @@ implementation
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.11 2001-03-03 12:41:22 jonas
|
Revision 1.12 2001-03-04 10:26:56 jonas
|
||||||
|
* new rangecheck code now handles conversion between signed and cardinal types correctly
|
||||||
|
|
||||||
|
Revision 1.11 2001/03/03 12:41:22 jonas
|
||||||
* simplified and optimized range checking code, FPC_BOUNDCHECK is no longer necessary
|
* simplified and optimized range checking code, FPC_BOUNDCHECK is no longer necessary
|
||||||
|
|
||||||
Revision 1.10 2000/12/31 11:02:12 jonas
|
Revision 1.10 2000/12/31 11:02:12 jonas
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user