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 |
条件式は、常に真か常に偽のどちらかとなります。
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.
| クラス名 | Redundant Condition | |||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | 冗長な条件 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| クラス分類 | 冗長性 (redundancy) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| ニーモニック | LANG.STRUCT.RC | |||||||||||||||||||||||||||||||||||||||||||||||||||
| カテゴリー |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
| 対応言語 | C および C++ で利用可能です。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
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.
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。