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.2p0 | CONFIDENTIAL | CodeSecure Inc |
Some condition is either always or never satisfied.
This includes conditions that are introduced by normalization rather than explicit in the code. Warnings for these cases also indicate a degree of redundancy in the analyzed code: see below for some examples.
| Class Name | Redundant Condition | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | redundancy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.STRUCT.RC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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="Redundant Condition" |
int lang_struct_rc_1(int i){
if (i > 0){ // ok: i>0 can be either true or false
if (i+1 > 1){ // 'Redundant Condition' warning issued here:
// if execution reaches this point, i+1>0 is true
return i;
}
}
return 0;
}
enum color { BLUE, RED, YELLOW };
bool process_bools(bool x, bool y){
return x && y;
}
bool lang_struct_rc_2(bool doNegate, bool andArg){
color colA = BLUE;
color colB = RED;
if (doNegate){ // ok: doNegate can be either true or false
return (bool)colA; // 'Redundant Condition' warning issued here:
// return (bool)colA;
// is normalized to the form
// if (colA != 0)
// TMP=true;
// else
// TMP=false;
// return TMP;
// and (colA != 0) is always true
//
// While the IF statement cited in the resulting warning report is not explicitly present
// in the code, the warning does signal the presence of redundancy:
// (bool)colA
// is functionally equivalent to
// false
// so neither the cast operation nor the colA variable is actually required.
}
return process_bools(colB, andArg); // 'Redundant Condition' warning issued here:
// negate(colB) coerces colB to bool, and this coercion is similarly
// normalized to an IF expression whose condition is (colB != 0)
//
// While the IF statement cited in the resulting warning report is not explicitly present
// in the code, the warning does signal the presence of redundancy:
// process_bools(colB, andArg)
// is functionally equivalent to
// process_bools(true, andArg)
// so the colB variable isn't required either.
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.