C and C++


LANG.CAST.PC.AV : 算術型とvoidポインタ間のキャスト

要旨

void ポインタと整数型の間でキャストされています。

例外:定数 0 から void ポインタへのキャストはこのクラスのワーニングを引き起こしません。

プロパティ

クラス名 Cast: Arithmetic Type/Void Pointer
日本語クラス名 算術型とvoidポインタ間のキャスト
クラス分類 スタイル (style)
ニーモニック LANG.CAST.PC.AV
カテゴリー
MisraC2023 MisraC2023:11.6 A cast shall not be performed between pointer to void and an arithmetic type
Misra2012 Misra2012:11.6 A cast shall not be performed between pointer to void and an arithmetic type
Misra2004 Misra2004:11.3 A cast should not be performed between a pointer type and an integral type
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
CERT-C CERT-C:INT31-C Ensure that integer conversions do not result in lost or misinterpreted data
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: Arithmetic Type/Void Pointer"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void use_pointers(void* p1, void *p2, void *p3);
void use_ints(int x, int y);

void PC_AtoV(int i){
    void *pv = (void *) i; /* 'Cast: Arithmetic Type/Void Pointer' warning issued here */
    void *cpv = i;                  /* not a cast */
    void *pnull = (void *) 0;       /* specific exception */
    use_pointers(pv, cpv, pnull);
}

void PC_VtoA(void *pv){
    int i = (int) pv;      /* 'Cast: Arithmetic Type/Void Pointer' warning issued here */
    int ci = pv;                    /* not a cast */
    use_ints(i, ci);
}

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

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