C and C++


LANG.CAST.PC.PV : voidポインタからオブジェクトポインタへの型変換

要旨

void型へのポインタがオブジェクトへのポインタにキャストされています。

例外:(NULL の様な) NULLポインタ定数からオブジェクトへのポインタへのキャストはこのクラスのワーニングを引き起こしません。

プロパティ

クラス名 Conversion: Void Pointer to Object Pointer
日本語クラス名 voidポインタからオブジェクトポインタへの型変換
クラス分類 スタイル (style)
ニーモニック LANG.CAST.PC.PV
カテゴリー
MisraC2023 MisraC2023:11.5 A conversion should not be performed from pointer to void into pointer to object
Misra2012 Misra2012:11.5 A conversion should not be performed from pointer to void into pointer to object
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
AUTOSARC++14 AUTOSARC++14:M5-2-8 An object with integer type or pointer to void type shall not be converted to an object with pointer type.
MisraC++2008 MisraC++2008:5-2-7 An object with pointer type shall not be converted to an unrelated pointer type, either directly or indirectly.
  MisraC++2008:5-2-8 An object with integer type or pointer to void type shall not be converted to an object with pointer type.
MisraC++2023 MisraC++2023:8.2.6 An object with integral, enumerated, or pointer to void type shall not be converted to an object with pointer 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
  TS17961:5.6-argcomp 5.6. Calling functions with incorrect arguments
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="Conversion: Void Pointer to Object Pointer"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

#include <stddef.h>

void use_pointers(int *p1, int *p2);

void PC_PV(void *v){
    int *i;
    int *j;

    i = (int *) v;        /* 'Conversion: Void Pointer to Object Pointer' warning issued here */
    j = (int *) NULL;                  /* specific exception */
    
    use_pointers(i,j);
}

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

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