mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 10:09:20 +02:00
* check for-loop constants ranges
This commit is contained in:
parent
8f2a768124
commit
16a60238c6
@ -276,6 +276,22 @@ implementation
|
|||||||
|
|
||||||
function for_statement : tnode;
|
function for_statement : tnode;
|
||||||
|
|
||||||
|
procedure check_range(hp:tnode);
|
||||||
|
begin
|
||||||
|
{$ifndef cpu64bit}
|
||||||
|
if hp.nodetype=ordconstn then
|
||||||
|
begin
|
||||||
|
if (tordconstnode(hp).value<low(longint)) or
|
||||||
|
(tordconstnode(hp).value>high(longint)) then
|
||||||
|
begin
|
||||||
|
CGMessage(parser_e_range_check_error);
|
||||||
|
{ recover, prevent more warnings/errors }
|
||||||
|
tordconstnode(hp).value:=0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$endif cpu64bit}
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
hp,
|
hp,
|
||||||
hloopvar,
|
hloopvar,
|
||||||
@ -387,6 +403,10 @@ implementation
|
|||||||
hto:=comp_expr(true);
|
hto:=comp_expr(true);
|
||||||
consume(_DO);
|
consume(_DO);
|
||||||
|
|
||||||
|
{ Check if the constants fit in the range }
|
||||||
|
check_range(hfrom);
|
||||||
|
check_range(hto);
|
||||||
|
|
||||||
{ first set the varstate for from and to, so
|
{ first set the varstate for from and to, so
|
||||||
uses of loopvar in those expressions will also
|
uses of loopvar in those expressions will also
|
||||||
trigger a warning when it is not used yet. This
|
trigger a warning when it is not used yet. This
|
||||||
@ -1157,7 +1177,10 @@ implementation
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.151 2005-01-31 20:23:53 peter
|
Revision 1.152 2005-02-03 17:10:58 peter
|
||||||
|
* check for-loop constants ranges
|
||||||
|
|
||||||
|
Revision 1.151 2005/01/31 20:23:53 peter
|
||||||
* set varstate before parsing the instruction block in for statements
|
* set varstate before parsing the instruction block in for statements
|
||||||
|
|
||||||
Revision 1.150 2005/01/31 16:16:21 peter
|
Revision 1.150 2005/01/31 16:16:21 peter
|
||||||
|
Loading…
Reference in New Issue
Block a user