MISRA C:2004 および MISRA AC AGC コーディング ルール
メモ
将来のリリースでは、Bug Finder で MISRA C™:2004 および MISRA™ AC AGC コーディング ルールへの準拠のチェックがサポートされなくなる予定です。これらの規約の代わりに、MISRA C:2023 規約を使用します。MISRA C:2023 のチェック (-misra-c-2023)
を参照してください。生成されたコードを解析する際は、MISRA C:2023 を使用し、オプション [生成されたコードの要件を使用] (-misra-c-2023-agc-mode)
を指定します。
サポートされている MISRA C:2004 および MISRA AC AGC ルール
次の表に、Polyspace™ コーディング ルール チェッカーでサポートされている MISRA C:2004 コーディング ルールを示します。各ルールのチェック方法およびチェック範囲の制限の詳細は、「Polyspace 仕様」列に記載されています。
メモ
Polyspace コーディング ルール チェッカーについて、次の点に注意してください。
ルール 4.1、5.1、5.3、6.1、6.3、7.1、9.2、10.5、12.6、13.5 および 15.0 については、MISRA-C:2004 Technical Corrigendum 1 をサポートしています。
「MISRA AC AGC Guidelines for the Application of MISRA-C:2004 in the Context of Automatic Code Generation」で規定されているルールをチェックします。
このソフトウェアでは、解析のコンパイル段階で違反の大部分が報告されます。ただし、ルール 9.1 (Non-initialized variable
)、12.11 (-scalar-overflows-checks signed-and-unsigned
を使用したオーバーフロー チェックの一種)、13.7 (デッド コード)、14.1 (デッド コード)、16.2 および 21.1 の違反は、コード解析時に検出され、ランタイム エラーとして報告されます。
メモ
ルール 13.7 および 14.1 の違反の一部は、解析のコンパイル段階で報告されます。
トラブルシューティング
ルール違反を想定していてもその違反が表示されない場合、コーディング規約違反が想定どおりに表示されない理由の診断を調査します。
サポートされているコーディング ルールのリスト
環境
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
1.1 | All code shall conform to ISO® 9899:1990 "Programming languages - C", amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996. |
| サポートされているすべての拡張機能は、この MISRA ルールの違反となります。標準のコンパイル エラー メッセージはこの MISRA ルールの違反にはならず、変更されません。 |
言語の拡張
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
2.1 | Assembly language shall be encapsulated and isolated. | Assembly language shall be encapsulated and isolated. | コードが以下でカプセル化されている場合、警告は出力されません。
|
2.2 | Source code shall only use /* */ style comments | C++ comments shall not be used. | C++ コメントはコメントとして処理されますが、この MISRA ルールの違反となります。 メモ: このルールについては、ソース コードに注釈を付けることができません。 |
2.3 | The character sequence /* shall not be used within a comment | The character sequence /* shall not appear within a comment. | このルール違反は C++ コメント内に文字列 /* がある場合も発生します。 メモ: このルールについては、ソース コードに注釈を付けることができません。 |
2.4 | Sections of code should not be "commented out" | Sections of code should not be "commented out" | チェッカーは内部でヒューリスティックな方法を使用してコメントアウトされたコードを検出します。たとえば、 チェッカーは、コードを含んでいても次のコメントに対してはフラグを設定しません。
チェッカーは、このようなコメントがドキュメンテーション目的か、または事前に考慮されたうえで意図的に入力されたものと見なします。 |
ドキュメンテーション
ルール | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
3.4 | All uses of the #pragma directive shall be documented and explained. | All uses of the #pragma directive shall be documented and explained. | このルールをチェックするには、オプション許可されるプラグマ (-allowed-pragmas) を使用してソース ファイルで許可されるプラグマをリストしなければなりません。Polyspace によって、許可されるプラグマ リストにないプラグマが検出された場合、違反になります。 |
文字セット
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
4.1 | Only those escape sequences which are defined in the ISO C standard shall be used. | \<character> is not an ISO C escape sequence Only those escape sequences which are defined in the ISO C standard shall be used. | |
4.2 | Trigraphs shall not be used. | Trigraphs shall not be used. | 3 文字表記は処理され、等価な文字に変換されますが、MISRA ルールの違反となります。 |
識別子
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
5.1 | Identifiers (internal and external) shall not rely on the significance of more than 31 characters | Identifier 'XX' should not rely on the significance of more than 31 characters. | すべての識別子 (グローバル、静的およびローカル) がチェックされます。 レビューを容易にするため、ルール チェッカーは、先頭の 31 文字が同じ識別子をすべて 1 つのルール違反として示します。ルール違反のイベント履歴内で識別子の名前が競合するすべてのインスタンスを確認できます。 このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされます。Polyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください。 |
5.2 | Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier. |
| ルール 8.1 に違反していないことを前提としています。 |
5.3 | A typedef name shall be a unique identifier | {typedef name}'%s' should not be reused. (already used as {typedef name} at %s:%d) | typedef 名が別の識別子名として再利用されている場合、警告されます。 |
5.4 | A tag name shall be a unique identifier | {tag name}'%s' should not be reused. (already used as {tag name} at %s:%d) | タグ名が別の識別子名として再利用されている場合、警告されます。 このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされます。Polyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください。 |
5.5 | No object or function identifier with a static storage duration should be reused. | {static identifier/parameter name}’%s’ should not be reused. (already used as {static identifier/parameter name} with static storage duration at %s:%d) | 静的な名前が別の識別子名として再利用されている場合、警告されます。 |
5.6 | No identifier in one name space should have the same spelling as an identifier in another name space, with the exception of structure and union member names. | {member name}'%s' should not be reused. (already used as {member name} at %s:%d) | ある名前空間の このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされます。Polyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください。 |
5.7 | No identifier name should be reused. | {identifier}'%s' should not be reused. (already used as {identifier} at %s:%d) | 次の場合、違反は報告されません。
|
型
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
6.1 | The plain char type shall be used only for the storage and use of character values | Only permissible operators on plain chars are '=', '==' or '!=' operators, explicit casts to integral types and '?' (for the 2nd and 3rd operands) | プレーンの char 型が、=、==、!= 以外の演算子と共に使用されている、整数型への明示的なキャストで使用されている、あるいは ? 演算子の第 2 オペランドまたは第 3 オペランドとして使用されている場合、警告されます。 |
6.2 | Signed and unsigned char type shall be used only for the storage and use of numeric values. |
| プレーンの char 型の値が符号付き char 型または符号なし char 型に暗黙的に変換されている場合、警告されます。 |
6.3 | typedefs that indicate size and signedness should be used in place of the basic types | typedefs that indicate size and signedness should be used in place of the basic types. | typedef の定義では、警告は出力されません。 |
6.4 | Bit fields shall only be defined to be of type unsigned int or signed int. | Bit fields shall only be defined to be of type unsigned int or signed int. | |
6.5 | Bit fields of type signed int shall be at least 2 bits long. | Bit fields of type signed int shall be at least 2 bits long. | 幅が 0 である無名の符号付き int 型ビット フィールドに対しては警告はありません。サイズが 1 以下であるすべての符号付きビット フィールドに適用されます (ルール 6.4 に違反している場合)。 |
定数
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
7.1 | Octal constants (other than zero) and octal escape sequences shall not be used. |
|
宣言と定義
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
8.1 | Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call. |
| 呼び出しで参照可能なプロトタイプは完全でなければなりません。 |
8.2 | Whenever an object or function is declared or defined, its type shall be explicitly stated | Whenever an object or function is declared or defined, its type shall be explicitly stated. | |
8.3 | For each function parameter the type given in the declaration and definition shall be identical, and the return types shall also be identical. | Definition of function 'XX' incompatible with its declaration. | ルール 8.1 に違反していないことを前提としています。このルールは互換性のある型に限定されます。オフにできます。 |
8.4 | If objects or functions are declared more than once their types shall be compatible. |
| このルールの違反はリンク段階で生成されることがあります。 このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされます。Polyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください。 |
8.5 | There shall be no definitions of objects or functions in a header file |
| 仮定義は定義と見なされます。ファイル スコープのオブジェクトの場合、仮定義は次のような宣言となります。
|
8.6 | Functions shall always be declared at file scope. | Function 'XX' should be declared at file scope. | このルールは ISO/IEC TS 17961 ID |
8.7 | Objects shall be defined at block scope if they are only accessed from within a single function | Object 'XX' should be declared at block scope. | 静的オブジェクトに限定されます。 |
8.8 | An external object or function shall be declared in one file and only one file | Function/Object 'XX' has external declarations in multiple files. | 明示的な外部宣言に制限されます (仮定義は無視されます)。 Polyspace では、ヘッダー ファイル以外で |
8.9 | An identifier with external linkage shall have exactly one external definition. |
| チェッカーでは、定義が異なるファイルに出現している場合にのみ、複数の定義にフラグを設定します。 事前定義されたシンボルへの警告はありません。 このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされます。Polyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください。 |
8.10 | All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required | Function/Variable XX should have internal linkage. | ルール 8.1 に違反していないことを前提としています。0 が使用されている場合、警告はありません。 コードに このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされます。Polyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください。 |
8.11 | The static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkage | static storage class specifier should be used on internal linkage symbol XX. | |
8.12 | When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization | Size of array 'XX' should be explicitly stated. |
初期化
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
9.1 | All automatic variables shall have been assigned a value before being used. | Polyspace は、コードに以下の問題が含まれている場合にこの違反を報告します。
| |
9.2 | Braces shall be used to indicate and match the structure in the nonzero initialisation of arrays and structures. | Braces shall be used to indicate and match the structure in the nonzero initialization of arrays and structures. | |
9.3 | In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized. | In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized. |
演算型変換
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
10.1 | The value of an expression of integer type shall not be implicitly converted to a different underlying type if:
|
| ANSI C 基本データ型の順序 (符号付きの char、short、int、long) は、T2 が T1 の右側にある場合は T2 が T1 よりも大きいか、T2 = T1 であることを意味します。符号なしの基本データ型にも同じ解釈が適用されます。 bool 型または enum 型の式は、int 型を潜在型としてもちます。 プレーンの char 型は、符号付きの基となる型をもつことも、符号なしの潜在型をもつこともあります (Polyspace のターゲット構成またはオプション設定に依存)。 struct.bitfield の単純な式の潜在型はビット フィールドの定義で使用される基本データ型です。ビット フィールドの幅は考慮されず、符号付きまたは符号なしの int 型のみがビット フィールドに使用されていることを前提としています (ルール 6.4)。 次の場合、違反は報告されません。
次のすべてに該当する場合、違反は報告されません。
ポインターを含む演算に対しては違反は報告されません。 あまりにも多くの違反にフラグ設定されるのを避けるため、このような場合には定数の変換は報告されません。定数をオリジナルの型でも変換後の型でも表現できる場合、変換はほとんど問題になりません。 |
10.2 | The value of an expression of floating type shall not be implicitly converted to a different type if
|
| ANSI C 基本データ型の順序 (float、double) は、T2 が T1 の右側にある場合は T2 が T1 よりも大きいか、T2 = T1 であることを意味します。 次の場合、違反は報告されません。
|
10.3 | The value of a complex expression of integer type may only be cast to a type that is narrower and of the same signedness as the underlying type of the expression | Complex expression of underlying type XX may only be cast to narrower integer type of same signedness, however the destination type is XX. |
|
10.4 | The value of a complex expression of float type may only be cast to narrower floating type | Complex expression of XX type may only be cast to narrower floating type, however the destination type is XX. | ANSI C 基本データ型の順序 (float、double) は、T2 が T1 の右側にある場合は T1 が T2 よりも小さいか、T2 = T1 であることを意味します。 |
10.5 | If the bitwise operator ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand | Bitwise [<<|~] is applied to the operand of underlying type [unsigned char|unsigned short], the result shall be immediately cast to the underlying type. | |
10.6 | The “U” suffix shall be applied to all constants of unsigned types | No explicit 'U suffix on constants of an unsigned type. | 値および基本データ型 (8 進、10 進または 16 進) から決定される型が符号なしであり、接尾辞 たとえば、 int a = 2147483648;
|
ポインター型変換
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
11.1 | Conversion shall not be performed between a pointer to a function and any type other than an integral type | Conversion shall not be performed between a pointer to a function and any type other than an integral type. | 関数ポインターを含むキャストおよび暗黙的な変換です。
|
11.2 | Conversion shall not be performed between a pointer to an object and any type other than an integral type, another pointer to an object type or a pointer to void | Conversion shall not be performed between a pointer to an object and any type other than an integral type, another pointer to an object type or a pointer to void. | 修飾子が失われる場合も警告があります。 このルールは ISO/IEC TS 17961 ID |
11.3 | A cast should not be performed between a pointer type and an integral type | A cast should not be performed between a pointer type and an integral type. | ゼロ定数は例外です。すべての変換に適用されます。 このルールは ISO/IEC TS 17961 ID |
11.4 | A cast should not be performed between a pointer to object type and a different pointer to object type. | A cast should not be performed between a pointer to object type and a different pointer to object type. | |
11.5 | A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer | A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer | すべての変換に適用されます。 |
式
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
12.1 | Limited dependence should be placed on C's operator precedence rules in expressions | Limited dependence should be placed on C's operator precedence rules in expressions | |
12.2 | The value of an expression shall be the same under any order of evaluation that the standard permits. |
| ルール 12.2 のチェックでは、ブール値が生成される式で代入を使用していないこと (ルール 13.1) を前提としています。 式は、シンボルの単純な式です。 |
12.3 | The | The | volatile アクセスについての警告はありません。 |
12.4 | The right hand operand of a logical && or || operator shall not contain side effects. | The right hand operand of a logical && or || operator shall not contain side effects. | volatile アクセスについての警告はありません。 |
12.5 | The operands of a logical && or || shall be primary-expressions. |
| 前処理時に、#if 命令の式でこのルールの違反が検出されます。 結合性による (a && b && c)、(a || b || c) は許容される例外です。 |
12.6 | Operands of logical operators (&&, || and !) should be effectively Boolean.Expression that are effectively Boolean should not be used as operands to operators other than (&&, || or !) |
| 論理演算子のオペランドは boolean データ型であることが必要です。C 標準では boolean データ型を明示的には定義していませんが、boolean データ型の使用を暗黙的に前提としています。 一部の演算子は boolean 形式の式を返すことがあります ( 以下のコードについて考えます。 unsigned char flag; if (!flag) ルール チェッカーにより、ルール 12.6 の違反が報告されます。 Operand of '!' logical operator should be effectively Boolean. flag は boolean ではなく、unsigned char です。ルール 12.6 に準拠するには、次のどちらかのようにコードを書き換えなければなりません。 if (!( flag != 0)) if (flag == 0) オプション |
12.7 | Bitwise operators shall not be applied to operands whose underlying type is signed |
| 次の場合、整数の潜在型は符号付きになります。
|
12.8 | The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left hand operand. |
| プリプロセッサ命令で操作される数値は 64 ビット幅であることから、有効なシフト範囲は 0 ~ 63 です。 このチェックは、フィールド幅、または基本データ型が複合式内にある場合その幅の、ビット フィールドにも適用されます。 |
12.9 | The unary minus operator shall not be applied to an expression whose underlying type is unsigned. |
| 次の場合、整数の潜在型は符号付きになります。
|
12.10 | The comma operator shall not be used. | The comma operator shall not be used. | |
12.11 | Evaluation of constant unsigned expression should not lead to wraparound. | Evaluation of constant unsigned integer expressions should not lead to wrap-around. | |
12.12 | The underlying bit representations of floating-point values shall not be used. | The underlying bit representations of floating-point values shall not be used. | 次の場合に警告されます。
|
12.13 | The increment (++) and decrement (--) operators should not be mixed with other operators in an expression | The increment (++) and decrement (--) operators should not be mixed with other operators in an expression | ++ または -- 演算子はそれのみで使用されていない場合、警告されます。 |
制御ステートメントの式
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
13.1 | Assignment operators shall not be used in expressions that yield Boolean values. | Assignment operators shall not be used in expressions that yield Boolean values. |
|
13.2 | Tests of a value against zero should be made explicit, unless the operand is effectively Boolean | Tests of a value against zero should be made explicit, unless the operand is effectively Boolean | 整数の定数に対しては警告は出力されません。例: if (2) オプション |
13.3 | Floating-point expressions shall not be tested for equality or inequality. | Floating-point expressions shall not be tested for equality or inequality. | 直接的なテストに対する警告です。 |
13.4 | The controlling expression of a for statement shall not contain any objects of floating type | The controlling expression of a for statement shall not contain any objects of floating type | インデックス for が変数シンボルである場合、浮動小数点型でないことがチェックされます。 |
13.5 | The three expressions of a for statement shall be concerned only with loop control |
| for ループ インデックス (V) が変数シンボルであるかどうかがチェックされます。最初の式が存在する場合、V が最後に代入される変数であるかどうかがチェックされます。最初の式が存在する場合、V の代入であるかどうかがチェックされます。2 番目の式が存在する場合、必ず V の比較であるかどうかがチェックされます。3 番目の式が存在する場合、必ず V の代入であるかどうかがチェックされます。 |
13.6 | Numeric variables being used within a for loop for iteration counting should not be modified in the body of the loop. | Numeric variables being used within a for loop for iteration counting should not be modified in the body of the loop. | for ループ インデックスが既知であり、かつ変数シンボルである場合、直接代入のみ検出します。 |
13.7 | Boolean operations whose results are invariant shall not be permitted |
| コンパイル時、チェッカーは少なくとも 1 つの定数オペランドとの比較を行います。
enum ec {RED, BLUE, GREEN} col; for(col=RED; col<=GREEN; col++) {} enum 変数は、範囲外にインクリメントされたときにラップ アラウンドできる可能性があるため、ループ条件が常に true にある場合があります。ルール違反を回避するには、次の例のように、比較前に enum を整数にキャストします。enum ec {RED, BLUE, GREEN} col; for(col=RED; (int)col<=GREEN; col++ ) {} |
制御フロー
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
14.1 | There shall be no unreachable code. | There shall be no unreachable code. | |
14.2 | All non-null statements shall either have at least one side effect however executed, or cause control flow to change | All non-null statements shall either:
| |
14.3 | 前処理の前では、null ステートメントはそれ自体のみが 1 行の中に現れなければなりません。ただし、null ステートメントに続く最初の文字が空白文字の場合は、その後にコメントを記述できます。 | A null statement shall appear on a line by itself | ';' は、その行の最初の文字である場合 (コメントを除く)、null ステートメントと見なされます。次の場合、このルールに違反します。
|
14.4 | The goto statement shall not be used. | The goto statement shall not be used. | |
14.5 | The continue statement shall not be used. | The continue statement shall not be used. | |
14.6 | For any iteration statement there shall be at most one break statement used for loop termination | For any iteration statement there shall be at most one break statement used for loop termination | |
14.7 | A function shall have a single point of exit at the end of the function | A function shall have a single point of exit at the end of the function | |
14.8 | The statement forming the body of a switch, while, do while or for statement shall be a compound statement |
| |
14.9 | An if (expression) construct shall be followed by a compound statement.The else keyword shall be followed by either a compound statement, or another if statement |
| |
14.10 | All if else if constructs should contain a final else clause. | All if else if constructs should contain a final else clause. |
switch ステートメント
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
15.0 | The MISRA C switch syntax shall be used. | switch statements syntax normative restrictions. | 最初の switch case の前にある宣言またはステートメントについて警告します。 switch case の本体にある label または jump ステートメントについて警告します。 次の例では、このルールがログ ファイルの行 3 に表示されています。 1 ... 2 switch(index) { 3 var = var + 1; // RULE 15.0 // violated 4case 1: ... switch ステートメントと最初の case の間にあるコードは、Polyspace によってデッド コードとしてチェックされます。これは ANSI 規格の動作に従います。 このルールは、生成されたコードでは MISRA C:2004 ルールの必要ルールと見なされません。生成されたコードでルール 15.0 の違反を見つけても、それがこのグループの後のルールに同時に違反しない場合は、適切なコメントでその違反を正当化します。 |
15.1 | A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement | A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement | |
15.2 | An unconditional break statement shall terminate every non-empty switch clause | An unconditional break statement shall terminate every non-empty switch clause | 準拠しない case 句ごとに警告が生成されます。 |
15.3 | The final clause of a switch statement shall be the default clause | The final clause of a switch statement shall be the default clause | |
15.4 | A switch expression should not represent a value that is effectively Boolean | A switch expression should not represent a value that is effectively Boolean | オプション |
15.5 | Every switch statement shall have at least one case clause | Every switch statement shall have at least one case clause |
関数
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
16.1 | Functions shall not be defined with variable numbers of arguments. | Function XX should not be defined as varargs. | |
16.2 | Functions shall not call themselves, either directly or indirectly. | Function %s should not call itself. | チェッカーは、それ自体を直接的または間接的に呼び出すそれぞれの関数について報告します。1 つの再帰サイクルに複数の関数が関与している場合でも、それぞれの関数が個別に報告されます。 再帰サイクルの総数は、コード複雑度メトリクス |
16.3 | Identifiers shall be given for all of the parameters in a function prototype declaration. | Identifiers shall be given for all of the parameters in a function prototype declaration. | ルール 8.6 に違反していないことを前提としています。 |
16.4 | The identifiers used in the declaration and definition of a function shall be identical. | The identifiers used in the declaration and definition of a function shall be identical. | ルール 8.8、8.1 および 16.3 に違反していないことを前提としています。 すべての出現箇所が検出されます。 |
16.5 | Functions with no parameters shall be declared with parameter type void. | Functions with no parameters shall be declared with parameter type void. | 定義もチェックされます。 |
16.6 | The number of arguments passed to a function shall match the number of parameters. |
| ルール 8.1 に違反していないことを前提としています。 このルールは ISO/IEC TS 17961 ID |
16.7 | A pointer parameter in a function prototype should be declared as pointer to | Pointer parameter in a function prototype should be declared as pointer to | 非 |
16.8 | All exit paths from a function with non-void return type shall have an explicit return statement with an expression. | Missing return value for non-void function XX. | 非 void 関数が、式をもつ無条件の return で終了していない場合、警告が生成されます。 |
16.9 | A function identifier shall only be used with either a preceding &, or with a parenthesized parameter list, which may be empty. | Function identifier XX should be preceded by a & or followed by a parameter list. | |
16.10 | If a function returns error information, then that error information shall be tested. | If a function returns error information, then that error information shall be tested. | チェッカーは、戻り値が使用されない場合や ただし、関数の |
ポインターと配列
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
17.1 | Pointer arithmetic shall only be applied to pointers that address an array or array element. | Pointer arithmetic shall only be applied to pointers that address an array or array element. | |
17.2 | Pointer subtraction shall only be applied to pointers that address elements of the same array | Pointer subtraction shall only be applied to pointers that address elements of the same array. | null ポインターまたは別の配列内の要素を指しているポインターを減算すると、Polyspace は違反を報告します。 |
17.3 | >, >=, <, <= shall not be applied to pointer types except where they point to the same array. | >, >=, <, <= shall not be applied to pointer types except where they point to the same array. | null ポインターまたは別の配列内の要素を指しているポインターを比較すると、Polyspace は違反を報告します。比較の関係演算子は > 、< 、>= 、および <= です。 |
17.4 | Array indexing shall be the only allowed form of pointer arithmetic. | Array indexing shall be the only allowed form of pointer arithmetic. | 以下に対する警告です。
|
17.5 | A type should not contain more than 2 levels of pointer indirection | A type should not contain more than 2 levels of pointer indirection | |
17.6 | The address of an object with automatic storage shall not be assigned to an object that may persist after the object has ceased to exist. | Pointer to a parameter is an illegal return value.Pointer to a local is an illegal return value. | グローバル変数へのアドレスの代入で、ローカル変数のアドレスまたはパラメーターのアドレスが返ると警告されます。 このルールは ISO/IEC TS 17961 ID |
構造体と共用体
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
18.1 | All structure or union types shall be complete at the end of a translation unit. | All structure or union types shall be complete at the end of a translation unit. | 不完全な構造体または共用体の宣言には警告が行われます。 |
18.2 | An object shall not be assigned to an overlapping object. |
| |
18.4 | Unions shall not be used | Unions shall not be used. |
プリプロセッサ命令
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
19.1 | #include statements in a file shall only be preceded by other preprocessors directives or comments | #include statements in a file shall only be preceded by other preprocessors directives or comments | A message is displayed when a #include directive is preceded by other things than preprocessor directives, comments, spaces or “new lines”. |
19.2 | Nonstandard characters should not occur in header file names in #include directives |
| |
19.3 | The #include directive shall be followed by either a <filename> or "filename" sequence. |
| |
19.4 | C macros shall only expand to a braced initializer, a constant, a parenthesized expression, a type qualifier, a storage class specifier, or a do-while-zero construct. | Macro `<name>' does not expand to a compliant construct. | マクロ定義は、以下に展開される場合、このルールに違反していないと見なされます。
|
19.5 | Macros shall not be #defined and #undefd within a block. |
| |
19.6 | #undef shall not be used. |
| |
19.7 | A function should be used in preference to a function like-macro. | A function should be used in preference to a function like-macro | すべての関数形式のマクロ定義のメッセージ。 |
19.8 | A function-like macro shall not be invoked without all of its arguments |
| |
19.9 | Arguments to a function-like macro shall not contain tokens that look like preprocessing directives. | Macro argument shall not look like a preprocessing directive. | マクロの引数内 (文字列定数または文字定数の外部) で '#' 文字が使用されている場合、このルールが違反として検出されます。 |
19.10 | In the definition of a function-like macro each instance of a parameter shall be enclosed in parentheses unless it is used as the operand of # or ##. | Parameter instance shall be enclosed in parentheses. |
パラメーターが関数または関数形式マクロの引数として再利用される場合、警告は生成されません。たとえば、パラメーター x について考えます。 |
19.11 | All macro identifiers in preprocessor directives shall be defined before use, except in #ifdef and #ifndef preprocessor directives and the defined() operator. | '<name>' is not defined. | |
19.12 | There shall be at most one occurrence of the # or ## preprocessor operators in a single macro definition. | More than one occurrence of the # or ## preprocessor operators. | |
19.13 | The # and ## preprocessor operators should not be used | Message on definitions of macros using # or ## operators | |
19.14 | The defined preprocessor operator shall only be used in one of the two standard forms. | 'defined' without an identifier. | |
19.15 | Precautions shall be taken in order to prevent the contents of a header file being included twice. | Precautions shall be taken in order to prevent multiple inclusions. | ヘッダー ファイルの形式 #ifndef <control macro> #define <control macro> <contents> #endif または #ifndef <control macro> #error ... #else #define <control macro> <contents> #endif この場合、複数回インクルードされないように安全対策が講じられていると見なされます。それ以外の場合は、この MISRA ルールの違反が検出されます。 |
19.16 | Preprocessing directives shall be syntactically meaningful even when excluded by the preprocessor. | directive is not syntactically meaningful. | |
19.17 | All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related. |
|
標準ライブラリ
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
20.1 | Reserved identifiers, macros and functions in the standard library, shall not be defined, redefined or undefined. |
| |
20.2 | The names of standard library macros, objects and functions shall not be reused. | Identifier XX should not be used. | 標準ライブラリのマクロ、オブジェクトおよび関数に一致する名前をもつマクロが定義されている場合、違反されたものとして検出されるルールは 20.1 です。 仮定義は定義と見なされます。ファイル スコープのオブジェクトの場合、仮定義は次のような宣言となります。
|
20.3 | The validity of values passed to library functions shall be checked. | Validity of values passed to library functions shall be checked | 次のすべてに該当する場合、ライブラリ関数の呼び出しの引数に対して、警告が生成されます。
ライブラリ関数は、 数学関数からなるカスタム ライブラリを使用することもあります。カスタム ライブラリ関数の領域と範囲が、標準ライブラリに含まれる別の関数の領域と範囲と同じであれば、そのカスタム ライブラリ関数をチェックするように、このチェッカーを拡張できます。標準ライブラリ関数用の Bug Finder チェッカーのカスタム ライブラリへの拡張を参照してください。 入力値が不明であり、入力のサブセットのみがエラーの原因として考えられる場合、既定の Bug Finder 解析ではこのルールに対する違反が報告されない場合があります。特定のシステム入力値を原因とする違反の有無をチェックするには、より厳密な Bug Finder 解析を実行してください。特定のシステム入力値から欠陥を見つけるための Bug Finder チェッカーの拡張を参照してください。 既定では、Bug Finder 解析は無限大と |
20.4 | Dynamic heap memory allocation shall not be used. |
| 動的ヒープ メモリ割り当て関数が実質的なマクロであり、このマクロがコードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。 |
20.5 | The error indicator errno shall not be used | The error indicator errno shall not be used | ルール 20.2 に違反していないことを前提としています。 |
20.6 | The macro offsetof, in library <stddef.h>, shall not be used. |
| ルール 20.2 に違反していないことを前提としています。 |
20.7 | The setjmp macro and the longjmp function shall not be used. |
| 関数 longjmp が実質的なマクロであり、マクロがコードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。 |
20.8 | The signal handling facilities of <signal.h> shall not be used. |
| 信号機能が実質的なマクロであり、そのマクロがコードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。 |
20.9 | The input/output library <stdio.h> shall not be used in production code. |
| 入出力ライブラリ関数が実質的なマクロであり、コードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。 |
20.10 | The library functions atof, atoi and atoll from library <stdlib.h> shall not be used. |
| 関数 atof、atoi および atoll が実質的なマクロであり、展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。 |
20.11 | The library functions abort, exit, getenv and system from library <stdlib.h> shall not be used. |
| 関数 abort、exit、getenv および system が実質的なマクロであり、展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。 |
20.12 | The time handling functions of library <time.h> shall not be used. |
| 時間処理関数が実質的なマクロとして展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。 |
実行時の失敗
番号 | MISRA 定義 | レポート ファイル メッセージ | Polyspace 実装 |
---|---|---|---|
21.1 | Minimization of runtime failures shall be ensured by the use of at least one of:
|
サポートされていない MISRA C:2004 および MISRA AC AGC ルール
Polyspace コーディング ルール チェッカーでは、以下の MISRA C:2004 コーディング ルールはチェックされません。これらのルールは Polyspace ソフトウェアの範囲外であるため、強制することはできません。これらは、MISRA ルールのドキュメンテーション、動的局面、機能的側面に関わるものです。「その他の情報」列には、各ルールがチェックされない理由が示されています。
環境
ルール | 説明 | その他の情報 |
---|---|---|
1.2 (必要) | No reliance shall be placed on undefined or unspecified behavior | データの動的な性質が考慮されない限り、静的にチェックすることはできません。 |
1.3 (必要) | Multiple compilers and/or languages shall only be used if there is a common defined interface standard for object code to which the language/compilers/assemblers conform. | これはプロセス ルールのメソッドです。 |
1.4 (必要) | The compiler/linker/Identifiers (internal and external) shall not rely on significance of more than 31 characters.Furthermore the compiler/linker shall be checked to ensure that 31 character significance and case sensitivity are supported for external identifiers. | このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。 |
1.5 (推奨) | Floating point implementations should comply with a defined floating point standard. | このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。 |
ドキュメンテーション
ルール | 説明 | その他の情報 |
---|---|---|
3.1 (必要) | All usage of implementation-defined behavior shall be documented. | このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。処理系定義の構造に対して行われた選択に応じて、未定義の動作に基づいてエラーが検出されます。 |
3.2 (必要) | The character set and the corresponding encoding shall be documented. | このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。 |
3.3 (推奨) | The implementation of integer division in the chosen compiler should be determined, documented and taken into account. | このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。 |
3.5 (必要) | The implementation-defined behavior and packing of bitfields shall be documented if being relied upon. | このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。 |
3.6 (必要) | All libraries used in production code shall be written to comply with the provisions of this document, and shall have been subject to appropriate validation. | このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。 |
構造体と共用体
ルール | 説明 | その他の情報 |
---|---|---|
18.3 (必要) | An area of memory shall not be reused for unrelated purposes. | "目的" とは機能設計に関する事柄です。 |