* disallow passing a dynarray(niln/pointerconstn) as an open array

(mantis #31273)

git-svn-id: trunk@37885 -
This commit is contained in:
Jonas Maebe 2017-12-31 15:18:40 +00:00
parent d385546d71
commit dcac6b9c6f
4 changed files with 43 additions and 1 deletions

2
.gitattributes vendored
View File

@ -14296,6 +14296,7 @@ tests/webtbf/tw31107.pp svneol=native#text/pascal
tests/webtbf/tw3114.pp svneol=native#text/plain
tests/webtbf/tw3116.pp svneol=native#text/plain
tests/webtbf/tw3126.pp svneol=native#text/plain
tests/webtbf/tw31273.pp svneol=native#text/plain
tests/webtbf/tw3145.pp svneol=native#text/plain
tests/webtbf/tw31465.pp svneol=native#text/pascal
tests/webtbf/tw3183.pp svneol=native#text/plain
@ -15854,6 +15855,7 @@ tests/webtbs/tw31165.pp svneol=native#text/pascal
tests/webtbs/tw31201.pp svneol=native#text/pascal
tests/webtbs/tw3124.pp svneol=native#text/plain
tests/webtbs/tw31246.pp svneol=native#text/pascal
tests/webtbs/tw31273a.pp svneol=native#text/plain
tests/webtbs/tw31305.pp svneol=native#text/pascal
tests/webtbs/tw3131.pp svneol=native#text/plain
tests/webtbs/tw31332.pp svneol=native#text/pascal

View File

@ -1704,6 +1704,8 @@ implementation
function ttypeconvnode.typecheck_dynarray_to_openarray : tnode;
begin
if (actualtargetnode(@left)^.nodetype in [pointerconstn,niln]) then
CGMessage(type_e_no_addr_of_constant);
{ a dynamic array is a pointer to an array, so to convert it to }
{ an open array, we have to dereference it (JM) }
result := ctypeconvnode.create_internal(left,cpointerdef.getreusable(resultdef));
@ -2913,7 +2915,9 @@ implementation
methodpointer. The typeconv of the methodpointer will then
take care of updateing size of niln to OS_64 }
if not((resultdef.typ=procvardef) and
not(tprocvardef(resultdef).is_addressonly)) then
not(tprocvardef(resultdef).is_addressonly)) and
{ converting (dynamic array) nil to a an open array is not allowed }
not is_open_array(resultdef) then
begin
left.resultdef:=resultdef;
if ([nf_explicit,nf_internal] * flags <> []) then

18
tests/webtbf/tw31273.pp Normal file
View File

@ -0,0 +1,18 @@
{ %fail }
{$mode delphi}
program Project1;
{$APPTYPE CONSOLE}
function SumX(const Arr: array of SizeInt): Integer;
begin
Result := Arr[Low(Arr)];
end;
var
P: Pointer;
begin
P := nil;
Writeln(SumX(TBoundArray(nil))); // Case 2
end.

18
tests/webtbs/tw31273a.pp Normal file
View File

@ -0,0 +1,18 @@
{$mode delphi}
program Project1;
{$APPTYPE CONSOLE}
function SumX(const Arr: array of SizeInt): Integer;
begin
if high(arr)<>-1 then
halt(1);
result:=1;
end;
var
P: Pointer;
begin
P := nil;
Writeln(SumX(TBoundArray(P))); // Case 1
end.