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

git-svn-id: trunk@11505 -
This commit is contained in:
florian 2008-08-03 10:34:41 +00:00
parent e0ff540918
commit d2214685c3
4 changed files with 42 additions and 32 deletions

1
.gitattributes vendored
View File

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

View File

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

View File

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

6
tests/tbf/tb0212.pp Normal file
View File

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