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.
Code Description Enabled Reported RETURN_INCONSISTENT Function has inconsistent return type Compilation (level 1) No declaration, returns nothing Compilation (level 2) Declared int, returns nothingCompilation (level 3) Declared non- int, returns nothingCompilation (level 4) Returns different types at different statements Compilation
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.
/*
* File: retinc.c
*/
void func() {
return;
}
/*
* File: retinc.c
*/
int func() {
return 0;
}
References
The table below shows Common Weakness Enumerations associated with this error.
| CWE | Description |
|---|---|
| CWE-758 | Reliance on undefined, unspecified, or implementation-defined behavior |