In this section:

Overview

Insure++ checks that each function returns a result consistent with its declared data type, and that a function with a declared return type actually returns an appropriate value.

Additional configuration required

In order for Insure++ to find this error, the suppressEDGWarning off option is required.

CodeDescriptionEnabledReportedPlatform
RETURN_INCONSISTENTFunction has inconsistent return type(error)CompilationWindows/Unix
(level 1)No declaration, returns nothing(error)CompilationWindows/Unix
(level 2)Declared int, returns nothing(tick)CompilationWindows/Unix
(level 3)Declared non-int, returns nothing(tick)CompilationWindows/Unix
(level 4)Returns different types at different statements(tick)CompilationWindows/Unix


Problem

The following code demonstrates an inconsistent return error:

/*
 * File: retinc.c
 */
func() {
	return;
}

Diagnosis During Compilation

[retinc.c:4] **RETURN_INCONSISTENT**
	Function has an inconsistent return type.
>> func() {

---- Associated Common Weakness Enumerations ----
CWE-758: Reliance on undefined, unspecified, or implementation-defined behavior
  • Line 1: Source line at which the problem was detected.
  • Line 2: Description of the error and the parameters used.
  • Line 5-6: CWE associated with this problem.

Repair

Correct inconsistent return errors by either adding appropriate declarations or by making the return type consistent with the function declaration.

Adding appropriate declarations
/*
 * File: retinc.c
 */
	void func() {
	return;
}
Consistency
/*
 * File: retinc.c
 */
int func() {
	return 0;
}

References

The table below shows Common Weakness Enumerations associated with this error.

CWEDescription
CWE-758Reliance on undefined, unspecified, or implementation-defined behavior
  • No labels