瀏覽代碼

* fixes compiler crash with out of memory on illegal array declarations

git-svn-id: trunk@11505 -
florian 17 年之前
父節點
當前提交
d2214685c3
共有 4 個文件被更改,包括 42 次插入32 次删除
  1. 1 0
      .gitattributes
  2. 33 32
      compiler/ptype.pas
  3. 2 0
      compiler/symdef.pas
  4. 6 0
      tests/tbf/tb0212.pp

+ 1 - 0
.gitattributes

@@ -6463,6 +6463,7 @@ tests/tbf/tb0208.pp svneol=native#text/plain
 tests/tbf/tb0209.pp svneol=native#text/plain
 tests/tbf/tb0210.pp svneol=native#text/plain
 tests/tbf/tb0211.pp svneol=native#text/plain
+tests/tbf/tb0212.pp svneol=native#text/plain
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain

+ 33 - 32
compiler/ptype.pas

@@ -623,7 +623,7 @@ implementation
           hdef      : tdef;
           arrdef    : tarraydef;
 
-          procedure setdefdecl(def:tdef);
+        procedure setdefdecl(def:tdef);
           begin
             case def.typ of
               enumdef :
@@ -666,8 +666,9 @@ implementation
              begin
                 { defaults }
                 indexdef:=generrordef;
-                lowval:=int64(low(aint));
-                highval:=high(aint);
+                { use defaults which don't overflow the compiler }
+                lowval:=0;
+                highval:=0;
                 repeat
                   { read the expression and check it, check apart if the
                     declaration is an enum declaration because that needs to
@@ -681,43 +682,43 @@ implementation
                    begin
                      pt:=expr;
                      if pt.nodetype=typen then
-                      setdefdecl(pt.resultdef)
+                       setdefdecl(pt.resultdef)
                      else
                        begin
-                          if (pt.nodetype=rangen) then
+                         if (pt.nodetype=rangen) then
                            begin
                              if (trangenode(pt).left.nodetype=ordconstn) and
                                 (trangenode(pt).right.nodetype=ordconstn) then
-                              begin
-                                { make both the same type or give an error. This is not
-                                  done when both are integer values, because typecasting
-                                  between -3200..3200 will result in a signed-unsigned
-                                  conflict and give a range check error (PFV) }
-                                if not(is_integer(trangenode(pt).left.resultdef) and is_integer(trangenode(pt).left.resultdef)) then
-                                  inserttypeconv(trangenode(pt).left,trangenode(pt).right.resultdef);
-                                lowval:=tordconstnode(trangenode(pt).left).value;
-                                highval:=tordconstnode(trangenode(pt).right).value;
-                                if highval<lowval then
-                                 begin
-                                   Message(parser_e_array_lower_less_than_upper_bound);
-                                   highval:=lowval;
-                                 end
-                                else if (lowval<int64(low(aint))) or
-                                        (highval > high(aint)) then
+                               begin
+                                 { make both the same type or give an error. This is not
+                                   done when both are integer values, because typecasting
+                                   between -3200..3200 will result in a signed-unsigned
+                                   conflict and give a range check error (PFV) }
+                                 if not(is_integer(trangenode(pt).left.resultdef) and is_integer(trangenode(pt).left.resultdef)) then
+                                   inserttypeconv(trangenode(pt).left,trangenode(pt).right.resultdef);
+                                 lowval:=tordconstnode(trangenode(pt).left).value;
+                                 highval:=tordconstnode(trangenode(pt).right).value;
+                                 if highval<lowval then
                                   begin
-                                    Message(parser_e_array_range_out_of_bounds);
-                                    lowval :=0;
-                                    highval:=0;
-                                  end;
-                                if is_integer(trangenode(pt).left.resultdef) then
-                                  range_to_type(lowval,highval,indexdef)
-                                else
-                                  indexdef:=trangenode(pt).left.resultdef;
-                              end
+                                    Message(parser_e_array_lower_less_than_upper_bound);
+                                    highval:=lowval;
+                                  end
+                                 else if (lowval<int64(low(aint))) or
+                                         (highval > high(aint)) then
+                                   begin
+                                     Message(parser_e_array_range_out_of_bounds);
+                                     lowval :=0;
+                                     highval:=0;
+                                   end;
+                                 if is_integer(trangenode(pt).left.resultdef) then
+                                   range_to_type(lowval,highval,indexdef)
+                                 else
+                                   indexdef:=trangenode(pt).left.resultdef;
+                               end
                              else
-                              Message(type_e_cant_eval_constant_expr);
+                               Message(type_e_cant_eval_constant_expr);
                            end
-                          else
+                         else
                            Message(sym_e_error_in_type_def)
                        end;
                      pt.free;

+ 2 - 0
compiler/symdef.pas

@@ -4378,6 +4378,8 @@ implementation
     constructor terrordef.create;
       begin
         inherited create(errordef);
+        { prevent consecutive faults }
+        savesize:=1;
       end;
 
 

+ 6 - 0
tests/tbf/tb0212.pp

@@ -0,0 +1,6 @@
+{ %fail }
+const
+  st : Array [False, True] of Char = ('F', 'U');
+
+begin
+end.