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 areturn
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.
Browse the function body for
return
statements.If you find a
return
statement:See if the
return
statement occurs in a block inside the function.For instance, the
return
statement occurs in anif
block. An execution path that does not enter theif
block bypasses thereturn
statement.See if you can identify the execution paths that bypass the
return
statement.For instance, an
if
block that contains thereturn
statement is bypassed for certain function inputs.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.