Pointer to non initialized value converted to const pointer
Pointer to constant assigned address that does not contain a value
Description
This defect occurs when a pointer to a constant (const int*
, const
char*
, etc.) is assigned an address that does not yet contain a
value.
For instance:
int x; const int * ptr = &x;
Risk
A pointer to a constant stores a value that must not be changed later in the program. If you assign the address of a non-initialized variable to the pointer, it now points to an address with garbage values for the remainder of the program.
Fix
Initialize a variable before assigning its address to a pointer to a constant.
Extend Checker
If a const
pointer is initialized incorrectly only for certain system input values, you can see one possible combination of input values causing the defect. See Extend Bug Finder Checkers to Find Defects from Specific System Input Values.
Examples
Result Information
Group: Data flow |
Language: C | C++ |
Default: Off |
Command-Line Syntax: NON_INIT_PTR_CONV |
Impact: Medium |
Version History
Introduced in R2013b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)