Insure++ Reference - RETURN_INCONSISTENT
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.
Because there are several different ways in which
functions and return values can be declared, Insure++ divides up
this error category into four levels or subcategories as follows:
Level 1
|
Function has no explicitly declared return type
(and so defaults to int ) and returns no value.
(This error level is normally suppressed.)
|
Level 2
|
Function is explicitly declared to return type int
but returns nothing.
|
Level 3
|
Function explicitly declared to return a data type
other than int but returns no value.
|
Level 4
|
The function returns a value of one type at one
statement and another data type at another statement.
|
In many applications, errors at levels 1 and 2 need to be suppressed,
since older codes often include these constructs.
The following code demonstrates the four different error levels.
1: /*
2: * File: retinc.c
3: */
4: func1() {
5: return;
6: }
7:
8: int func2() {
9: return;
10: }
11:
12: double func3() {
13: return;
14: }
15:
16: int func4(a)
17: int a;
18: {
19: if (a < 3) return a;
20: return;
21: }
1. [retinc.c:4] **RETURN_INCONSISTENT(1)**
2. Function func1 has an inconsistent return type.
Declared return type implicitly "int",
but returns no value.
>> func1() {
[retinc.c:8] **RETURN_INCONSISTENT(2)**
Function func2 has an inconsistent return type.
Declared return type "int", but returns no value.
>> int func2() {
[retinc.c:12] **RETURN_INCONSISTENT(3)**
Function func2 has an inconsistent return type.
Declared return type "double", but returns no value.
>> double func3() {
[retinc.c:20] **RETURN_INCONSISTENT(4)**
Function func4 has an inconsistent return type.
Returns value in one location, and not in another.
>> return;
- Source line at which the problem was detected.
- Description of the error and the parameters used.
As already suggested, older codes often generate errors at levels 1
and 2 which are not particularly serious. You can either correct these
problems by adding suitable declarations or suppress them by adding the
option
insure++.suppress RETURN_INCONSISTENT(1, 2)
to your .psrc file.
Errors at levels 3 and 4 should probably be investigated and corrected.
RETURN_FAILURE
UNUSED_VAR
|