When memory integrity checks are enabled, if the code generator
detects that a loop variable might overflow on the last iteration
for-loop, it reports an error.
To avoid this error, use the workarounds provided in the following table.
|Loop conditions causing the error||Workaround|
Rewrite the loop so that the end value is not equal to the maximum value of the integer type. For example, replace:
N=intmax('int16') for k=N-10:N
Rewrite the loop so that the end value is not equal to the minimum value of the integer type. For example, replace:
N=intmin('int32') for k=N+10:-1:N
The loop covers the full range of the integer type.
Rewrite the loop casting the type of the loop counter start, step, and end values to a bigger integer or to double For example, rewrite:
M= intmin('int16'); N= intmax('int16'); for k=M:N % Loop body end
M= intmin('int16'); N= intmax('int16'); for k=int32(M):int32(N) % Loop body end
The software error checking is conservative. It may incorrectly report a loop as being potentially infinite.
Rewrite the loop so that the loop variable on the last loop iteration is equal to the end value.