mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-24 00:59:07 +02:00
* fix type conversion for array indicies if the ordinal ranges of the involved types do not overlap, resolves #38413
git-svn-id: trunk@48449 -
This commit is contained in:
parent
89149a2f9f
commit
e99827246e
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -18649,6 +18649,7 @@ tests/webtbs/tw38385.pp svneol=native#text/pascal
|
|||||||
tests/webtbs/tw38390.pp svneol=native#text/pascal
|
tests/webtbs/tw38390.pp svneol=native#text/pascal
|
||||||
tests/webtbs/tw3840.pp svneol=native#text/plain
|
tests/webtbs/tw3840.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw3841.pp svneol=native#text/plain
|
tests/webtbs/tw3841.pp svneol=native#text/plain
|
||||||
|
tests/webtbs/tw38413.pp svneol=native#text/pascal
|
||||||
tests/webtbs/tw3863.pp svneol=native#text/plain
|
tests/webtbs/tw3863.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw3864.pp svneol=native#text/plain
|
tests/webtbs/tw3864.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw3865.pp svneol=native#text/plain
|
tests/webtbs/tw3865.pp svneol=native#text/plain
|
||||||
|
@ -1051,7 +1051,16 @@ implementation
|
|||||||
and not is_64bit(right.resultdef)
|
and not is_64bit(right.resultdef)
|
||||||
{$endif not cpu64bitaddr}
|
{$endif not cpu64bitaddr}
|
||||||
then
|
then
|
||||||
newordtyp:=Torddef(right.resultdef).ordtype
|
begin
|
||||||
|
{ in case of an integer type, we need a new type which covers declaration range and index range,
|
||||||
|
see tests/webtbs/tw38413.pp
|
||||||
|
}
|
||||||
|
if is_integer(right.resultdef) then
|
||||||
|
newordtyp:=range_to_basetype(min(TConstExprInt(Tarraydef(left.resultdef).lowrange),torddef(right.resultdef).low),
|
||||||
|
max(TConstExprInt(Tarraydef(left.resultdef).highrange),torddef(right.resultdef).high))
|
||||||
|
else
|
||||||
|
newordtyp:=Torddef(right.resultdef).ordtype;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
newordtyp:=torddef(sizesinttype).ordtype;
|
newordtyp:=torddef(sizesinttype).ordtype;
|
||||||
inserttypeconv(right,corddef.create(newordtyp,
|
inserttypeconv(right,corddef.create(newordtyp,
|
||||||
|
12
tests/webtbs/tw38413.pp
Normal file
12
tests/webtbs/tw38413.pp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
var
|
||||||
|
arr : array[-1..140] of byte=(4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||||
|
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||||
|
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
|
||||||
|
index , value : byte; // unsigned byte - important
|
||||||
|
begin
|
||||||
|
index:=133; // positive value, which is treated as negative
|
||||||
|
value:=arr[index]; // wrong value! Memory access outside array
|
||||||
|
if value<>4 then
|
||||||
|
halt(1);
|
||||||
|
writeln('ok');
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user