C and C++


LANG.TYPE.ICA : 文字型の不適切な演算

要旨

実質的な文字型の式が、 加算もしくは減算演算のオペランドとして使用されています。
但し、以下のケースはチェックから除外します。

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

プロパティ

クラス名 Inappropriate Character Arithmetic
日本語クラス名 文字型の不適切な演算
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.ICA
カテゴリー
MisraC2023 MisraC2023:10.2 Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations
Misra2012 Misra2012:10.2 Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations
Misra2004 Misra2004:6.1 The plain char type shall be used only for storage and use of character values
AUTOSARC++14 AUTOSARC++14:M4-5-3 Expressions with type (plain) char and wchar_t shall not be used as operands to built-in operators other than the assignment operator =, the equality operators == and ! =, and the unary & operator.
  AUTOSARC++14:M5-0-11 The plain char type shall only be used for the storage and use of character values.
  AUTOSARC++14:M5-0-12 Signed char and unsigned char type shall only be used for the storage and use of numeric values.
MisraC++2008 MisraC++2008:4-5-3 Expressions with type (plain) char and wchar_t shall not be used as operands to built-in operators other than the assignment operator = , the equality operators == and != , and the unary & operator.
  MisraC++2008:5-0-11 The plain char type shall only be used for the storage and use of character values.
  MisraC++2008:5-0-12 signed char and unsigned char type shall only be used for the storage and use of numeric values.
MisraC++2023 MisraC++2023:7.0.3 The numerical value of a character shall not be used
CERT-C CERT-C:STR04-C Use plain char for characters in the basic character set
DISA-6r1 DISA-6r1:V-222612 The application must not be vulnerable to overflow attacks.
DISA-5r3 DISA-5r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-4r3 DISA-4r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-3r10 DISA-3r10:V-16808 The designer will ensure the application is not vulnerable to integer arithmetic issues.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inappropriate Character Arithmetic"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void TYPE_ICA(void){
    char c;
    int x;

    c = 'A' + 3;                                       /* permitted case */
    c = 4 + 'A';                                       /* permitted case */
    x = 'A' + 'B';     /* 'Inappropriate Character Arithmetic' warning issued here */

    c = 'A' - 3;                                       /* permitted case */
    c = 'A' - 4.5;     /* 'Inappropriate Character Arithmetic' warning issued here */
    c = 3 - 'A';       /* 'Inappropriate Character Arithmetic' warning issued here */
    x = 'Z' - 'A';                                     /* permitted case */
}

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

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