Static Analysis False Positives

Static analysis cannot always determine whether an apparent execution path is possible or combinations of variable values are possible. As a result, static analysis will sometimes report false positives - potential errors that are not actually possible. While it is not possible to eliminate false positives, the Intel Inspector does allow you to mark an issue as a false positive and subsequently hide it from view. The following are a few examples that illustrate how false positives occur.

Example: Incorrect Message About Division by 0

In this example, static analysis calculates that the set of possible values for x are {6,3} and the set of possible values for y are {3,0}. Static analysis does not know that the combination of values where x and y are both equal to 3 is impossible, so it issues a false positive error about a possible divide-by-zero error on line 4.

1  #include <stdio.h>
3  double mysub(int x, int y) {
4     return 1 / (x - y);
5  }
7  int main(int argc, char **argv) {
8     int x,y;
9     if (argc > 3) {
10       x = 6;
11       y = 3;
12    } else {
13       x = 3;
14       y = 0;
15    }
16    printf("%f\n", mysub(x, y));
17    return 0;
18 }

Example: Incorrect Message About Uninitialized Variable

In this example, there are two if statements. Static analysis sees an apparent execution path through the false part of the first if statement and the true part of the second if statement. If this path were executed, then the variable j would be used without being initialized. Static analysis does not know that this path is impossible because the two if conditions are in fact equivalent, so it issues a false positive error saying that the variable j may be uninitialized on line 9.

1  #include <stdio.h>
3  int main(int argc, char **argv) {
4     int j;
5     if ((argc & 1) == 0) {
6        j = argc;
7     }
8     if (((argc >> 1) << 1) == argc) {
9        printf("%d\n", j);
10    }
11    return 0;
12 }

See Also

Supplemental documentation specific to a particular Intel Studio may be available at <install-dir>\<studio>\documentation\ .

For more complete information about compiler optimizations, see our Optimization Notice.