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

git-svn-id: trunk@22434 -
This commit is contained in:
Jonas Maebe 2012-09-21 22:42:30 +00:00
parent ca5fabda6d
commit 5ea03973d3
4 changed files with 31 additions and 5 deletions

1
.gitattributes vendored
View File

@ -11844,6 +11844,7 @@ tests/webtbf/tw22665b.pp svneol=native#text/plain
tests/webtbf/tw2273.pp svneol=native#text/plain
tests/webtbf/tw2281.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/tw2359.pp svneol=native#text/plain
tests/webtbf/tw2362.pp svneol=native#text/plain

View File

@ -189,7 +189,7 @@ implementation
;
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;
@ -1504,6 +1504,14 @@ implementation
end;
vecn :
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 }
not gotvec and
not(valid_packed in opts) and
@ -1843,20 +1851,20 @@ implementation
function valid_for_var(p:tnode; report_errors: boolean):boolean;
begin
valid_for_var:=valid_for_assign(p,[],report_errors);
valid_for_var:=valid_for_assign(p,[valid_range],report_errors);
end;
function valid_for_formal_var(p : tnode; report_errors: boolean) : boolean;
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;
function valid_for_formal_const(p : tnode; report_errors: boolean) : boolean;
begin
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;

View File

@ -621,7 +621,11 @@ implementation
{ test if node can be assigned, properties are allowed }
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 }
if is_dynamic_array(left.resultdef) and

13
tests/webtbf/tw22941.pp Normal file
View File

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