Skip to content

Commit 506dba5

Browse files
committed
fbc: adjust the range checks on 'FOR counter variable is unable to exceed limit value'
1 parent 43b47f4 commit 506dba5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/compiler/parser-compound-for.bas

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ sub cForStmtBegin( )
835835
end if
836836

837837
if( stk->for.end.sym = NULL and stk->for.ispos.sym = NULL ) then
838-
dim as integer toobig = 0
838+
dim as integer toobig = FALSE
839839
if ( stk->for.ispos.value.i ) then
840840
select case as const typeGetSizeType( stk->for.cnt.dtype )
841841
case FB_SIZETYPE_INT8
@@ -862,11 +862,13 @@ sub cForStmtBegin( )
862862
case FB_SIZETYPE_INT8
863863
toobig = (stk->for.end.value.i <= -128)
864864
case FB_SIZETYPE_INT16
865-
toobig = (stk->for.end.value.i >= -32768)
865+
toobig = (stk->for.end.value.i <= -32768)
866866
case FB_SIZETYPE_INT32
867-
toobig = (stk->for.end.value.i >= -2147483648)
867+
toobig = (stk->for.end.value.i <= -2147483648)
868868
case FB_SIZETYPE_INT64
869-
toobig = (stk->for.end.value.i >= -9223372036854775808)
869+
'' can't test with '<=' comparison here otherwise
870+
'' condition is always true on 64-bit integer counters
871+
toobig = (stk->for.end.value.i = -9223372036854775808)
870872
end select
871873
end if
872874
if( toobig ) then

0 commit comments

Comments
 (0)