Static Analysis Problem Type Reference
The exit condition in a "while" loop is loop-invariant.
A loop invariant expression is one that does not change as the loop executes. Typically, it is an error for a loop condition to be loop invariant. If the loop condition is false, then the loop will execute zero times. Otherwise, the loop condition will never become false and the loop will execute forever. This usually indicates a coding error.
|
ID |
Code Location |
Description |
|---|---|---|
|
1 |
Memory read |
The location of the loop with the invariant condition |
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int j, k, n;
k = rand();
n = rand();
for (j = 0; k == n; j++) {
printf("%d\n", j);
}
return 0;
}