C and C++


LANG.CAST.PC.AO : 非算術型とオブジェクトポインタ間のキャスト

要旨

オブジェクトへのポインタ型と以下の型の間でキャストしています。
'実質的なブール型'、'実質的な文字型'、'実質的な列挙型'、'実質的な浮動小数点型' (MISRA C 2012 の定義)。

プロパティ

クラス名 Cast: Non-integer Arithmetic Type/Object Pointer
日本語クラス名 非算術型とオブジェクトポインタ間のキャスト
クラス分類 信頼性 (reliability)
ニーモニック LANG.CAST.PC.AO
カテゴリー
MisraC2023 MisraC2023:11.7 A cast shall not be performed between pointer to object and a non-integer arithmetic type
Misra2012 Misra2012:11.7 A cast shall not be performed between pointer to object and a non-integer arithmetic type
Misra2004 Misra2004:11.2 Conversions shall not be performed between a pointer to object and any type other than an integral type, another pointer to object type or a pointer to void
CWE CWE:704 Incorrect Type Conversion or Cast
TS17961 TS17961:5.1-ptrcomp 5.1. Accessing an object through a pointer to an incompatible type
JSF++ JSF++:182 Type casting from any type to or from pointers shall not be used.
  JSF++:183 Every possible measure should be taken to avoid type casting.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Cast: Non-integer Arithmetic Type/Object Pointer"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void use_pointers(int* x, int *y);
void use_chars(char a, char b);

void PC_AtoO(char c){
    int *pi = (int *)c; /* 'Cast: Non-integer Arithmetic Type/Object Pointer' warning issued here */
    int *cpi = c;              /* not a cast */
    use_pointers(pi, cpi);
}

void PC_OtoA(int *pi){
    char c = (char) pi; /* 'Cast: Non-integer Arithmetic Type/Object Pointer' warning issued here */
    char cc = pi;              /* not a cast */
    use_chars(c, cc);
}

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

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