When memory integrity checks are enabled, if the code generator
detects that a loop variable might overflow on the last iteration
of the 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 for k=1:10 | |
| 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 for k=10:-1:1 | |
| 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 | |
| Rewrite the loop so that the loop variable on the last loop iteration is equal to the end value. |