Explorar el Código

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

git-svn-id: trunk@37885 -

Jonas Maebe hace 7 años
padre
commit
dcac6b9c6f
Se han modificado 4 ficheros con 43 adiciones y 1 borrados
  1. 2 0
      .gitattributes
  2. 5 1
      compiler/ncnv.pas
  3. 18 0
      tests/webtbf/tw31273.pp
  4. 18 0
      tests/webtbs/tw31273a.pp

+ 2 - 0
.gitattributes

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

+ 5 - 1
compiler/ncnv.pas

@@ -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 - 0
tests/webtbf/tw31273.pp

@@ -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 - 0
tests/webtbs/tw31273a.pp

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