Main Content

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.

  1. Find previous instances where write operations are performed on the pointer.

  2. 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. The if 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.

VariableHow to Find Previous Operations on Variable

Local Variable

Use one of the following methods:

  • Search for the variable.

    1. Right-click the variable. Select Search For All References.

      All instances of the variable appear on the Search pane with the current instance highlighted.

    2. On the Search pane, select the previous instances.

  • Browse the source code.

    1. On the Source pane, double-click the variable.

      All instances of the variable are highlighted.

    2. Scroll up to find the previous instances.

Global Variable

Right-click the variable. If the option Show In Variable Access View appears, the variable is a global variable.

  1. Select the option Show In Variable Access View.

    The current instance of the variable is shown on the Variable Access pane.

  2. On this pane, select the previous instances of the variable.

    Write operations on the variable are indicated with . Read operations are indicated with .

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: