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.ICA : Inappropriate Character Arithmetic

Summary

An expression of essentially character type is used as an operand in an addition or subtraction operation, unless one of the following applies.

This warning class utilizes the notion of essential type category as described in MISRA C:2012 Guidelines for the use of the C language in critical systems.

Properties

Class Name Inappropriate Character Arithmetic
Significance style
Mnemonic LANG.TYPE.ICA
Categories
MisraC2025 MisraC2025:10.2 Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations
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.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inappropriate Character Arithmetic"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

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 */
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

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