Ver Fonte

* reject assignments to vecn[rangen] (mantis #22941)

git-svn-id: trunk@22434 -
Jonas Maebe há 13 anos atrás
pai
commit
5ea03973d3
4 ficheiros alterados com 31 adições e 5 exclusões
  1. 1 0
      .gitattributes
  2. 12 4
      compiler/htypechk.pas
  3. 5 1
      compiler/nld.pas
  4. 13 0
      tests/webtbf/tw22941.pp

+ 1 - 0
.gitattributes

@@ -11844,6 +11844,7 @@ tests/webtbf/tw22665b.pp svneol=native#text/plain
 tests/webtbf/tw2273.pp svneol=native#text/plain
 tests/webtbf/tw2273.pp svneol=native#text/plain
 tests/webtbf/tw2281.pp svneol=native#text/plain
 tests/webtbf/tw2281.pp svneol=native#text/plain
 tests/webtbf/tw2285.pp svneol=native#text/plain
 tests/webtbf/tw2285.pp svneol=native#text/plain
+tests/webtbf/tw22941.pp svneol=native#text/plain
 tests/webtbf/tw2357.pp svneol=native#text/plain
 tests/webtbf/tw2357.pp svneol=native#text/plain
 tests/webtbf/tw2359.pp svneol=native#text/plain
 tests/webtbf/tw2359.pp svneol=native#text/plain
 tests/webtbf/tw2362.pp svneol=native#text/plain
 tests/webtbf/tw2362.pp svneol=native#text/plain

+ 12 - 4
compiler/htypechk.pas

@@ -189,7 +189,7 @@ implementation
        ;
        ;
 
 
     type
     type
-      TValidAssign=(Valid_Property,Valid_Void,Valid_Const,Valid_Addr,Valid_Packed);
+      TValidAssign=(Valid_Property,Valid_Void,Valid_Const,Valid_Addr,Valid_Packed,Valid_Range);
       TValidAssigns=set of TValidAssign;
       TValidAssigns=set of TValidAssign;
 
 
 
 
@@ -1504,6 +1504,14 @@ implementation
                end;
                end;
              vecn :
              vecn :
                begin
                begin
+                 if (tvecnode(hp).right.nodetype=rangen) and
+                    not(valid_range in opts) then
+                  begin
+                    if report_errors then
+                      CGMessagePos(tvecnode(hp).right.fileinfo,parser_e_illegal_expression);
+                    mayberesettypeconvs;
+                    exit;
+                  end;
                  if { only check for first (= outermost) vec node }
                  if { only check for first (= outermost) vec node }
                     not gotvec and
                     not gotvec and
                     not(valid_packed in opts) and
                     not(valid_packed in opts) and
@@ -1843,20 +1851,20 @@ implementation
 
 
     function  valid_for_var(p:tnode; report_errors: boolean):boolean;
     function  valid_for_var(p:tnode; report_errors: boolean):boolean;
       begin
       begin
-        valid_for_var:=valid_for_assign(p,[],report_errors);
+        valid_for_var:=valid_for_assign(p,[valid_range],report_errors);
       end;
       end;
 
 
 
 
     function  valid_for_formal_var(p : tnode; report_errors: boolean) : boolean;
     function  valid_for_formal_var(p : tnode; report_errors: boolean) : boolean;
       begin
       begin
-        valid_for_formal_var:=valid_for_assign(p,[valid_void],report_errors);
+        valid_for_formal_var:=valid_for_assign(p,[valid_void,valid_range],report_errors);
       end;
       end;
 
 
 
 
     function  valid_for_formal_const(p : tnode; report_errors: boolean) : boolean;
     function  valid_for_formal_const(p : tnode; report_errors: boolean) : boolean;
       begin
       begin
         valid_for_formal_const:=(p.resultdef.typ=formaldef) or
         valid_for_formal_const:=(p.resultdef.typ=formaldef) or
-          valid_for_assign(p,[valid_void,valid_const,valid_property],report_errors);
+          valid_for_assign(p,[valid_void,valid_const,valid_property,valid_range],report_errors);
       end;
       end;
 
 
 
 

+ 5 - 1
compiler/nld.pas

@@ -621,7 +621,11 @@ implementation
 
 
         { test if node can be assigned, properties are allowed }
         { test if node can be assigned, properties are allowed }
         if not(nf_internal in flags) then
         if not(nf_internal in flags) then
-          valid_for_assignment(left,true);
+          if not valid_for_assignment(left,true) then
+            { errors can in situations that cause the compiler to run out of
+              memory, such as assigning to an implicit pointer-to-array
+              converted node (that array is 2^31 or 2^63 bytes large) }
+            exit;
 
 
         { assigning nil to a dynamic array clears the array }
         { assigning nil to a dynamic array clears the array }
         if is_dynamic_array(left.resultdef) and
         if is_dynamic_array(left.resultdef) and

+ 13 - 0
tests/webtbf/tw22941.pp

@@ -0,0 +1,13 @@
+{ %fail }
+
+program test;
+
+{$mode objfpc}
+{$h+}
+
+var
+  s: string;
+
+begin
+  s[1..3] := '123';
+end.