Main Content

Global Variables in Polyspace Bug Finder

When you run a Bug Finder™ analysis, Polyspace® makes certain assumptions about the initialization of global variables. These assumptions depend on how you declare and define global variables. For example, in this code

int foo(void) {
    return 1/gvar;
}
Bug Finder detects a division by zero defect with the variable gvar in these cases:

  • You define int gvar; in the source code and provide a main function that calls foo. Bug Finder follows ANSI standards that state the variable is initialized to zero.

  • You define int gvar; or declare extern int gvar; in the source code. Another function calls foo and sets gvar=0. Otherwise, when your source files are incomplete and do not contain a main function, Bug Finder makes no assumption about the initialization of gvar.

  • You declare const int gvar;. Bug Finder assumes gvar is initialized to zero due to the const keyword.

At the cost of a possibly longer runtime, you can perform a more exhaustive analysis where all values are considered for each read of a global variable by foo or of its callees when showing defects. See Extend Bug Finder Checkers to Find Defects from Specific System Input Values.

See Also

|