Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/error.bas
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ declare function hMakeParamDesc _
( /'FB_WARNINGMSG_RETURNTYPEMISMATCH '/ 0, @"Return type mismatch" ), _
( /'FB_WARNINGMSG_CALLINGCONVMISMATCH '/ 0, @"Calling convention mismatch" ), _
( /'FB_WARNINGMSG_ARGCNTMISMATCH '/ 0, @"Argument count mismatch" ), _
( /'FB_WARNINGMSG_SUFFIXIGNORED '/ 1, @"Suffix ignored" ) _
( /'FB_WARNINGMSG_SUFFIXIGNORED '/ 1, @"Suffix ignored" ), _
( /'FB_WARNINGMSG_FORENDTOOBIG '/ 1, @"FOR counter variable is unable to exceed limit value" ) _
}

dim shared errorMsgs( 1 to FB_ERRMSGS-1 ) as const zstring ptr => _
Expand Down
1 change: 1 addition & 0 deletions src/compiler/error.bi
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ enum FB_WARNINGMSG
FB_WARNINGMSG_CALLINGCONVMISMATCH
FB_WARNINGMSG_ARGCNTMISMATCH
FB_WARNINGMSG_SUFFIXIGNORED
FB_WARNINGMSG_FORENDTOOBIG

FB_WARNINGMSGS
end enum
Expand Down
40 changes: 40 additions & 0 deletions src/compiler/parser-compound-for.bas
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,46 @@ sub cForStmtBegin( )
hUdtFor( stk )
end if

if( stk->for.end.sym = NULL and stk->for.ispos.sym = NULL ) then
dim as integer toobig = 0
if ( stk->for.ispos.value.i ) then
select case as const typeGetSizeType( stk->for.cnt.dtype )
case FB_SIZETYPE_INT8
toobig = (stk->for.end.value.i >= 127)
case FB_SIZETYPE_UINT8
toobig = (stk->for.end.value.i >= 255)
case FB_SIZETYPE_INT16
toobig = (stk->for.end.value.i >= 32767)
case FB_SIZETYPE_UINT16
toobig = (stk->for.end.value.i >= 65535)
case FB_SIZETYPE_INT32
toobig = (stk->for.end.value.i >= 2147483647)
case FB_SIZETYPE_UINT32
toobig = (stk->for.end.value.i >= 4294967295)
case FB_SIZETYPE_INT64
toobig = (culngint(stk->for.end.value.i) >= 9223372036854775807)
case FB_SIZETYPE_UINT64
toobig = (culngint(stk->for.end.value.i) >= 18446744073709551615)
end select
else
select case as const typeGetSizeType( stk->for.cnt.dtype )
case FB_SIZETYPE_UINT8, FB_SIZETYPE_UINT16, FB_SIZETYPE_UINT32, FB_SIZETYPE_UINT64
toobig = (stk->for.end.value.i <= 0)
case FB_SIZETYPE_INT8
toobig = (stk->for.end.value.i <= -128)
case FB_SIZETYPE_INT16
toobig = (stk->for.end.value.i >= -32768)
case FB_SIZETYPE_INT32
toobig = (stk->for.end.value.i >= -2147483648)
case FB_SIZETYPE_INT64
toobig = (stk->for.end.value.i >= -9223372036854775808)
end select
end if
if( toobig ) then
errReportWarn( FB_WARNINGMSG_FORENDTOOBIG )
end if
end if

'' if inic, endc and stepc are all constants,
'' check if this branch is needed
if( isconst = 3 ) then
Expand Down
16 changes: 16 additions & 0 deletions tests/warnings/for-limit-too-big.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#macro testForLimits(T, L, U)
for i as T = 0 to U
next i
for i as T = 0 to L step -1
next i
#endmacro

testForLimits(ubyte, 0, 255)
testForLimits(ushort, 0, 65535)
testForLimits(ulong, 0, 4294967295)
testForLimits(ulongint, 0, 18446744073709551615)

testForLimits(byte, -128, 127)
testForLimits(short, -32768, 32767)
testForLimits(long, -2147483648, 2147483647)
testForLimits(longint, -9223372036854775808, 9223372036854775807)
16 changes: 16 additions & 0 deletions tests/warnings/r/dos/for-limit-too-big.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
16 changes: 16 additions & 0 deletions tests/warnings/r/linux-x86/for-limit-too-big.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
16 changes: 16 additions & 0 deletions tests/warnings/r/linux-x86_64/for-limit-too-big.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
16 changes: 16 additions & 0 deletions tests/warnings/r/win32/for-limit-too-big.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
16 changes: 16 additions & 0 deletions tests/warnings/r/win64/for-limit-too-big.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value
FOR counter variable is unable to exceed limit value