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
C and C++
Ada
Java
C#
Binaries


MISC.CPE : Copy-Pasteエラー

要旨

2つのコード領域は、構造的に高い類似性がありますが、完全一致しているわけではありません。

このチェッカーは、コードをコピーして新しいコンテキストにペーストした時に、 セマンティクスが維持されない形で変更調整されているケースを識別することを目的としています。 例えば、とあるコードを新しいコンテキストにペーストした際、 本来は全ての変数名をリネームすべきだったところ、 一つか若しくはそれ以上の変数が正しくリネームされずに残っているという状態を検出することができます。

誤検出が多く発生することを避ける為、 CodeSonarは2つのコード領域がかなり複雑なケースのみ 検出するように調整されています。

プロパティ

クラス名 Copy-Paste Error
日本語クラス名 Copy-Pasteエラー
クラス分類 信頼性 (reliability)
ニーモニック MISC.CPE
カテゴリー
CWE CWE:1041 Use of Redundant Code
対応言語 Available for all languages.
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Copy-Paste Error"

int MISC_CPE(int a, int b, int c) {
    int x = 0;
    int y = 0;
        
    if (a > 5){
        x = x + a;
        y = y + a;
    }

    if (b > 5){
        x = x + b;
        y = y + a;  /* "Copy-Paste Error" warning issued here:
                     * CodeSonar suspects that this was copy-pasted from the first IF statement
                     * and then then some - but not all - occurrences of variable a changed to b   */
    }

    if (c > 5){
        x = x + c;
        y = y + c;               /* ok  */
    }

    return x+y;
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.