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;
}gvar in these cases:
You define
int gvar;in the source code and provide amainfunction that callsfoo. Bug Finder follows ANSI standards that state the variable is initialized to zero.You define
int gvar;or declareextern int gvar;in the source code. Another function callsfooand setsgvar=0. Otherwise, when your source files are incomplete and do not contain amainfunction, Bug Finder makes no assumption about the initialization ofgvar.You declare
const int gvar;. Bug Finder assumesgvaris initialized to zero due to theconstkeyword.
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
Inputs in Polyspace Bug Finder | Bug Finder Analysis Assumptions