Main Content

Review and Fix Function Not Returning Value Checks

This topic describes how to systematically review the results of a Function not returning value check in Polyspace® Code Prover™.

Follow one or more of these steps until you determine a fix for the Function not returning value check. For a description of the check and code examples, see Function not returning value.

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. The Result Details pane displays further information about the check.

You can see:

  • The immediate cause of the check.

    In this example, the software has identified that a function with a non-void return type might not have a return statement.

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

    In this example, the software has identified that the check is possibly path-related. More than one call to the function exists, and the check is green on at least one call.

Step 2: Determine Root Cause of Check

Determine why a return statement does not exist on certain execution paths.

  1. Browse the function body for return statements.

  2. If you find a return statement:

    1. See if the return statement occurs in a block inside the function.

      For instance, the return statement occurs in an if block. An execution path that does not enter the if block bypasses the return statement.

    2. See if you can identify the execution paths that bypass the return statement.

      For instance, an if block that contains the return statement is bypassed for certain function inputs.

    3. If the function is called multiple times in your code, you can identify which function call led to bypassing of the return statement. Use the option Sensitivity Context to determine the check color for each function call.

Possible fix: If the return type of the function is incorrect, change it. Otherwise, add a return statement on all execution paths. For instance, if only a fraction of branches of an if-else if-else condition have a return statement, add a return statement in the remaining branches. Alternatively, add a return statement outside the if-else if-else condition.