Review and Fix Non-initialized Pointer Checks
This topic describes how to systematically review the results of a Non-initialized pointer check in Polyspace® Code Prover™.
Follow one or more of these steps until you determine a fix for the Non-initialized
pointer check. There are multiple ways to fix this check. For a
description of the check and code examples, see Non-initialized pointer
.
Sometimes, especially for an orange check, you can determine that the check does not represent a real error but a Polyspace assumption that is not true for your code. If you can use an analysis option to relax the assumption, rerun the verification using that option. Otherwise, you can add a comment and justification in your result or code.
For the general workflow that applies to all checks, see Interpret Code Prover Results in Polyspace Desktop User Interface or Interpret Code Prover Results in Polyspace Access Web Interface (Polyspace Access).
Step 1: Interpret Check Information
Select the check on the Results List pane. On the Result Details pane, obtain further information about the check.
Step 2: Determine Root Cause of Check
Right-click the pointer variable and select Go To Definition. Initialize the variable when you define it. If you do not want to initialize during definition, identify a suitable point to initialize the variable before you read it.
For orange checks, determine why the pointer is non-initialized on certain execution paths.
Find previous instances where write operations are performed on the pointer.
For each write operation, determine if the operation occurs:
Before the read operation containing the orange Non-initialized pointer check.
Possible fix: If the write operation occurs after the read operation, see if you intended to perform the operations in reverse order.
In an unreachable code block.
Possible fix: Investigate why the code block is unreachable. See Review and Fix Unreachable Code Checks.
In a code block that is not reached on certain execution paths. For example, the operation occurs in an
if
block in a function. Theif
block is not entered for certain function inputs.Possible fix: Perform a write operation on all the execution paths. In the preceding example, perform the write operation in all branches of the
if ... elseif ... else
statement.
Depending on the nature of the variable, use the appropriate method to find previous operations on the variable. You can perform the following steps in the Polyspace user interface only.
Variable | How to Find Previous Operations on Variable |
---|---|
Local Variable | Use one of the following methods:
|
Global Variable Right-click the variable. If the option Show In Variable Access View appears, the variable is a global variable. |
|
Step 3: Trace Check to Polyspace Assumption
See if you can trace the orange check to a Polyspace assumption that occurs earlier in the code. If the assumption does not hold true in your case, add a comment or justification in your result or code. See Address Results in Polyspace User Interface Through Bug Fixes or Justifications or Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access).
Disabling This Check
You can disable the check in two ways:
You can disable the check only for non-local pointers. Polyspace considers global pointer variables to be initialized to
NULL
according to ANSI® C standards. For more information, see Ignore default initialization of global variables.You can disable the check completely along with other initialization checks. If you disable this check, Polyspace assumes that at declaration, pointers can be
NULL
or point to memory blocks at an unknown offset. For more information, seeDisable checks for non-initialization (-disable-initialization-checks)
.