JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
Some of the code in a function is not reachable from the function entry point under any circumstances.
The following table lists the available unreachable code warning classes in order of severity, with the most severe ("Unreachable Call") first. The warning class associated with a block of unreachable code will be the most severe class that is applicable to the statements in the block.
| Warning Class Name | Most Serious Statement Type in Unreachable Set |
|---|---|
| Unreachable Call | A call site. |
| Unreachable Computation | A statement that performs computation (such as addition) on data. |
| Unreachable Conditional | A branch statement, such as if, while, switch, ?, &&,||. |
| Unreachable Data Flow | A simple assignment, or a return statement with a value. |
| Unreachable Control Flow | A non-branching statement that influences control flow, such as break, goto, continue, or return with no value. |
Multiple warning classes share this mnemonic.
To enable or disable them all at once, add one of the following WARNING_FILTER rules to the project configuration file.
WARNING_FILTER += allow categories:LANG.STRUCT.UC WARNING_FILTER += discard categories:LANG.STRUCT.UC
| Class Name | Unreachable Call | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | redundancy | |||||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.STRUCT.UC | |||||||||||||||||||||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
|||||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Unreachable Call" |
| Class Name | Unreachable Computation | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | redundancy | ||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.STRUCT.UC | ||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Unreachable Computation" |
| Class Name | Unreachable Conditional | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | redundancy | ||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.STRUCT.UC | ||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Unreachable Conditional" |
| Class Name | Unreachable Control Flow | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | redundancy | ||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.STRUCT.UC | ||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
WARNING_FILTER += allow class="Unreachable Control Flow" |
| Class Name | Unreachable Data Flow | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | redundancy | ||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.STRUCT.UC | ||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Unreachable Data Flow" |
#include <stdlib.h>
#include <stddef.h>
void g(void);
int f(int i){
if( i ) exit( i );
return 0;
}
/* For unreachable_computation(), unreachable_conditional(),
* unreachable_conditional(), and unreachable_data_flow(), the first
* statement in the function body is
* int rv = f(5);
*
* The call to f() is reachable but never returns, so the remainder of
* the function, including the assignment of the return value to rv
* that takes place in the same statement, is unreachable. (This
* assignment is itself a data flow.) The warning class for each of
* these cases will depend on the nature of the statements in the
* unreachable block.
*/
int unreachable_call(int x){
int p;
int rv = f(5); /* 'Unreachable Call' warning issued here */
g(); /* call (highest severity) */
rv += x; /* computation */
if (x>5) { /* conditional */
return 0; /* data flow */
}
p = rv; /* data flow */
return p;
}
int unreachable_computation(int x){
int p;
int rv = f(5); /* 'Unreachable Computation' warning issued here */
rv += x; /* computation (highest severity) */
if (x>5) { /* conditional */
return 0; /* data flow */
}
p = rv; /* data flow */
return p;
}
int unreachable_conditional(int x){
int p;
int rv = f(5); /* 'Unreachable Conditional' warning issued here */
if (x>5) { /* conditional (highest severity) */
return 0; /* data flow */
}
p = rv; /* data flow */
return p;
}
int unreachable_data_flow(){
int p;
int rv = f(5); /* 'Unreachable Data Flow' warning issued here */
p = rv; /* data flow */
return p;
}
/* In unreachable_control_flow(), a return statement is unreachable
* because it is in the TRUE branch of an IF statement whose condition
* always evaluates to FALSE.
*/
void unreachable_control_flow(int x, int y){
char *q = NULL;
while (q==NULL){
q = (char *) malloc(5 * sizeof(char));
}
if (q==NULL) { /* ('Redundant Condition' warning issued here) */
return; /* 'Unreachable Control Flow' warning issued here */
}
free(q);
}
The following configuration file parameters affect checks for this warning class.