JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.TYPE.ICT : 不適切な型へのキャスト

要旨

式の値が、以下の表に記載されている実質的な型に不適切にキャストされています。

式の実質的な型 不適切なキャストとなる実質的な型
essentially Boolean essentially character, essentially enum, essentially signed, essentially unsigned, essentially real floating, essentially complex floating
essentially character essentially Boolean, essentially enum, essentially real floating, essentially complex floating
essentially enum essentially Boolean, essentially enum (except casts to exactly the same enum, which would be redundant)
essentially signed essentially Boolean, essentially enum
Exception: an integer constant expression with value 0 or 1 can be cast to an essentially Boolean type.
essentially unsigned essentially Boolean, essentially enum
Exception: an integer constant expression with value 0 or 1 can be cast to an essentially Boolean type.
essentially real floating essentially Boolean, essentially character, essentially enum
essentially complex floating essentially Boolean, essentially character, essentially enum

このワーニングクラスは、クリティカルシステム向けのC言語ガイドラインMISRA C:2012実質的な型に記載されている概念に基づいています。

プロパティ

クラス名 Inappropriate Cast Type
日本語クラス名 不適切な型へのキャスト
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.ICT
カテゴリー
MisraC2025 MisraC2025:10.5 The value of an expression should not be cast to an inappropriate essential type
MisraC2023 MisraC2023:10.5 The value of an expression should not be cast to an inappropriate essential type
Misra2012 Misra2012:10.5 The value of an expression should not be cast to an inappropriate essential type
CWE CWE:704 Incorrect Type Conversion or Cast
JSF++ JSF++:184 Floating point numbers shall not be converted to integers unless such a conversion is a specified algorithmic requirement or is necessary for a hardware interface.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inappropriate Cast Type"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

typedef enum {GO, PROCEED_WITH_CAUTION, STOP} action;
typedef enum {GREEN, ORANGE, RED} light;

char LANG_TYPE_ICT(action a, char ch){
  light lt;
  float f;

  if (ch)
    lt = a;                                    /* not an explicit cast ('Mixed enum Type' warning issued) */
  else
    lt = (light) a;       /* 'Inappropriate Cast Type' warning issued here */

  if (lt > 1)
    f = (float) ch;       /* 'Inappropriate Cast Type' warning issued here */
  else
    f = (float) (lt==0);  /* 'Inappropriate Cast Type' warning issued here */

  if (f > 5)
    return (char) a;                          /* permissible cast for this warning class */
  else
    return 'X';
}

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

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

 

To report problems with this documentation, please visit https://support.codesecure.com/.