C and C++


LANG.CAST.PC.FLOAT : 浮動小数点ポインタと異なる型のポインタとの型変換

要旨

ポインタ型 fl* からポインタ型 T*、若しくはポインタ型 T* からポインタ型 fl*へのキャスト若しくは型強制が行われています。尚:

プロパティ

クラス名 Float Pointer Conversion
日本語クラス名 浮動小数点ポインタと異なる型のポインタとの型変換
クラス分類 スタイル (style)
ニーモニック LANG.CAST.PC.FLOAT
カテゴリー
Misra2004 Misra2004:12.12 The underlying bit representations of floating-point values shall not be used
AUTOSARC++14 AUTOSARC++14:M3-9-3 The underlying bit representations of floating-point values shall not be used.
MisraC++2008 MisraC++2008:3-9-3 The underlying bit representations of floating-point values shall not be used.
CWE CWE:704 Incorrect Type Conversion or Cast
  CWE:710 Improper Adherence to Coding Standards
JSF++ JSF++:147 The underlying bit representations of floating point numbers shall not be used in any way by the programmer.
  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="Float Pointer Conversion"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

double * to_floatptr(float *fptr, void* vptr, int *intptr, long  int i ){
    float *localfptr;
    double d = (double) i;                       /* no pointer conversion */
    localfptr = (float *) &d;  /* 'Float Pointer Conversion' warning issued here (cast from double* to float*) */

    switch (i) {
    case 1:
        fptr = intptr;         /* 'Float Pointer Conversion' warning issued here (coercion from int* to float*) */
        break;
    case 2:
    fptr = (float*) intptr;    /* 'Float Pointer Conversion' warning issued here (cast  from int* to float*) */
        break;
    case 3:
        fptr = i;                                /* ok: coercion from non-pointer to float* */
        break;
    case 4:
        *fptr = *localfptr;                      /* no pointer conversion */
        break;
    default:
        fptr = vptr;                             /* ok: coercion from void* to float* */
    break;
    }
    return fptr;               /* 'Float Pointer Conversion' warning issued here (coercion from float* to double*) */
}

int from_floatptr(float *fptr, double d, int i){
    int localint = (int)fptr;                    /* ok: cast from float* to non-pointer */
    int *iptr;
    void *vptr = fptr;                           /* ok: coercion from float* to void* */

    switch (i){
    case 1:
        iptr = fptr;           /* 'Float Pointer Conversion' warning issued here (coercion from float* to int*) */
        break;
    case 2:
        iptr = (int *)&d;      /* 'Float Pointer Conversion' warning issued here (cast from double* to int*) */
        break;
    default:
        iptr = vptr;                             /* no float pointer involved */
        break;
    }
    return *iptr + localint;                     /* no float pointer involved */
}

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

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