Main Content

Review and Fix Incorrect Object Oriented Programming Checks

This topic describes how to systematically review the results of an Incorrect object oriented programming check in Polyspace® Code Prover™.

Follow one or more of these steps until you determine a fix for the Incorrect object oriented programming check. For a description of the check and code examples, see Incorrect object oriented programming.

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

On the Results List pane, select the check. The Result Details pane displays further information about the check.

You can see:

  • The immediate cause of the check. For instance:

    • You dereference a function pointer that has the value NULL or points to an invalid member function.

      The member function is invalid if its argument or return type does not match the pointer argument or return type.

    • You call a pure virtual member function of a class from the class constructor or destructor.

    • You call a member function using an incorrect this pointer.

      To see why the this pointer can be incorrect, see Incorrect object oriented programming.

  • The probable root cause of the check, if indicated.

Step 2: Determine Root Cause of Check

If you cannot determine the root cause based on the check information, use navigation shortcuts in the user interface to navigate to the root cause.

Based on the specific error, use one of the following methods to find the root cause.

ErrorHow to Find Root Cause
You dereference a function pointer that has the value NULL.

Right-click the function pointer and select Search For All References. Find the instance where you assign NULL to the function pointer.

You dereference a function pointer that points to an invalid member function.

Compare the argument and return types of the function pointer and the member function that it points to.

  1. Right-click the function pointer on the Source pane and select Search For All References. Find the instances where you:

    • Define the function pointer.

    • Assign the address of a member function to the function pointer.

  2. Find the member function definition. Right-click the member function name on the Source pane and select Go To Definition.

You call a pure virtual member function from a constructor or destructor.

Find the member function declaration and determine whether you intended to declare it as virtual or pure virtual. Alternatively, determine if you can replace the call to the pure virtual function with another operation, for instance, a call to a different member function.

  1. Right-click the function name on the Source pane and select Search for function_name in All Source Files.

  2. Find the function declaration from the search results.

    A pure virtual function has a declaration such as:

    virtual void func() = 0;

You call a member function using an incorrect this pointer.

Determine why the this pointer is incorrect.

For instance, if a red Incorrect object oriented programming check appears on a function call ptr->func() and the message indicates that the this pointer is incorrect, trace the data flow for ptr.

  • Right-click the function pointer on the Source pane and select Search For All References.

  • Browse through all write operations on the pointer. Look for the following issues:

    • Cast between pointers of unrelated types.

    • Pointer arithmetic that takes a pointer outside its allocated buffer, for instance, the bounds of an array.

If a red Incorrect object oriented programming check appears on a function call obj.func(), trace the data flow for obj. See if obj is not initialized previously.