ホーム/ドキュメント/コーディング規約/CppDepend で Cert C コンプライアンスをシームレスに達成

CppDepend で Cert C コンプライアンスをシームレスに達成

CppDepend で Cert C コンプライアンスをシームレスに達成

今日の競争の激しいソフトウェア開発環境では、高品質で安全なコードの維持が不可欠です。Cert C コーディング標準は、信頼性が高く安全な C アプリケーションを作成するためのガイドラインとして機能します。しかし、開発者はプロジェクトで Cert C コンプライアンスをどのように効率的に達成できるでしょうか?

CppDepend の登場です。これは、Cert C 標準の複雑さをナビゲートするのを支援するために特別に設計された包括的なツールです。静的解析技術を活用することで、CppDepend はコンプライアンスへと導くだけでなく、コード全体の品質とセキュリティを向上させる力を与えてくれます。

CERT C標準を学ぶには、これを印刷できます SEI CERT Cコーディング標準ドキュメント カーネギーメロン大学による。

CppDependでのCERT Cルールの使用

新しい CppDepend プロジェクトを作成すると、分析に含めたいすべてのコーディング標準を表示するポップアップが表示されます。Cert C コーディング標準を含めるには、Cert オプションをチェックして Cert C を選択します。

CERT Cルール設定

プロジェクトを分析した後、Queries and Rules Explorer セクションに移動し、左側のメニューから Cert C Rules を選択します(下の画像で赤く強調表示)。これにより、関連するすべての Cert C ルールが右側に表示されます。ルールをクリックすると、対応する CQLinq クエリと関連するソースコードが自動的に生成されます。さらに、Metrics View セクションでは、問題の場所と重要性のビジュアライゼーションが提供されます。

CERT Cルールエクスプローラー

CERT C ルールの HTML レポートへの組み込み

生成された HTML レポート(DevOps Edition で利用可能)に Cert C ルールを含めるには、Cert C グループを右クリックして「List Code Queries of this Group in a dedicated section in Report」を選択するだけです。

レポート内のCERT Cルール

CERT Cルール一覧

プリプロセッサ (PRE)

PRE30-C: Do not create a universal character name through concatenation:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_ucn_escape_incomplete"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

PRE31-C: Avoid side effects in arguments to unsafe macros:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="bugprone-macro-repeated-side-effects"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

宣言と初期化

DCL30-C: Declare objects with appropriate storage durations:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="danglingLifetime"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

DCL31-C: 使用前に識別子を宣言:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="err_missing_type_specifier"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

DCL37-C:Do not declare or define a reserved identifier:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_pp_macro_is_reserved_id" select
new { issue,issue.FilePath,Line=issue.BeginLine}

DCL41-C: Do not declare variables inside a switch statement before the first case label:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.Type=="Rule6-4-4"
select new { issue,issue.FilePath,Line=issue.BeginLine}

式 (Exp)

EXP30-C: Do not depend on the order of evaluation for side effects:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_unsequenced_mod_use" select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP32-C: Do not access a volatile object through a nonvolatile reference:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang"
&& issue.Type=="err_typecheck_convert_incompatible_volatile"  select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP33-C: 未初期化メモリを読まないこと:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && (issue.Type=="uninitvar" || issue.Type=="uninitdata") select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP34-C: NULLポインタを逆参照しないこと:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="nullPointer"  select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP35-C: Do not modify objects with temporary lifetime:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang"
&& issue.Type=="err_typecheck_expression_not_modifiable_lvalue"  select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP36-C: Do not cast pointers into more strictly aligned pointer types:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_cast_align" select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP37-C: Call functions with the correct number and type of arguments:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="err_typecheck_call_too_many_args" select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP39-C: Do not access a variable through a pointer of an incompatible type:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="invalidPointerCast" select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP40-C: 定数オブジェクトを変更しないこと:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="err_typecheck_convert_incompatible_const" select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP44-C: Do not rely on side effects in operands to sizeof,\_Alignof, or \_Generic:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_side_effects_unevaluated_context"
&& issue.Description.Contains(("lambda")) select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP45-C:Do not perform assignments in selection statements:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_condition_is_assignment" select
new { issue,issue.FilePath,Line=issue.BeginLine}

EXP46-C. Do not use a bitwise operator with a Boolean-like operand:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0**
from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_precedence_bitwise_rel" select
new { issue,issue.FilePath,Line=issue.BeginLine}

浮動小数点 (FLP)

FLP30-C:Do not use floating-point variables as loop counters:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="cert-flp30-c"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

FLP34-C: Ensure that floating-point conversions are within range of the new type:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_impcast_float_integer"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

配列 (ARR)

ARR30-C. Do not form or use out-of-bounds pointers or array subscripts:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="arrayIndexOutOfBounds"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

ARR36-C: Do not subtract or compare two pointers that do not refer to the same array:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="comparePointers"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

ARR39-C: Do not add or subtract a scaled integer to a pointer:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_ptr_arith_exceeds_bounds"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

文字と文字列 (STR)

STR30-C: Do not attempt to modify string literals:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="stringLiteralWrite"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

STR34-C: Cast characters to unsigned char before converting to larger integer sizes:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="bugprone-signed-char-misuse"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

メモリ管理 (MEM)

MEM30-C: 解放されたメモリにアクセスしないこと:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="nullPointer"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

MEM31-C. Free dynamically allocated memory when no longer needed:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang" && issue.Type=="warn_mismatched_delete_new"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

入出力 (FIO)

FIO38-C: FILEオブジェクトをコピーしないこと:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="cert-fio38-c"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

FIO42-C: Close files when they are no longer needed:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="resourceLeak"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

環境 (ENV)

ENV33-C: system()を呼ばないこと:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="CppCheck" && issue.Type=="nullPointer"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

シグナル (SIG)

SIG30-C: Call only asynchronous-safe functions within signal handlers:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="bugprone-signal-handler"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

エラー処理 (ERR)

ERR34-C: Detect errors when converting a string to a number:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="cert-err34-c"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

並行性 (CON)

CON36-C. Wrap functions that can spuriously wake up in a loop:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="bugprone-spuriously-wake-up-functions"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

その他 (MSC)

MSC30-C: Do not use the rand() function for generating pseudorandom numbers:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="cert-msc30-c"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

MSC32-C: Properly seed pseudorandom number generators:

このコーディング標準は次のクエリで計算されます:

warnif **count** > **0** from issue in **ImportedIssues** where issue.ToolName=="Clang-Tidy" && issue.Type=="cert-msc32-c"
select new { issue, issue.FilePath, Line = issue.BeginLine ,
Debt = **10**.ToMinutes().ToDebt(),
Severity =Severity.High
}

今すぐCppDependを試す

ドキュメントの全機能にアクセスできる14日間無料トライアル。クレジットカード不要。