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.MOT : Mismatched Operand Types

Summary

For an operator that performs the 'usual arithmetic conversions' (as described in the C90 and C99 standards), the two operands do not have the same essential type category. This check applies to

Exception 1: for binary + and +=, a warning of this class will not be issued if one operand has essentially character type and the other has essentially signed type or essentially unsigned type.

Exception 2: for binary - and -=, a warning of this class will not be issued if the LHS operand has essentially character type and the RHS operand has essentially signed type or essentially unsigned type.

Exception 3: a warning of this class will not be issued if one operand has essentially real floating type and the other has essentially complex floating type. (For the ternary ?: operator, this exception applies to the second and third operands.)

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 Mismatched Operand Types
Significance style
Mnemonic LANG.TYPE.MOT
Categories
MisraC2025 MisraC2025:10.4 Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category
MisraC2023 MisraC2023:10.4 Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category
Misra2012 Misra2012:10.4 Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category
Misra2004 Misra2004:6.1 The plain char type shall be used only for storage and use of character values
  Misra2004:6.2 signed and unsigned char type shall be used only for the storage and use of numeric values
  Misra2004:10.1 The value of an expression of integer type shall not be implicitly converted to a different underlying type if: (a) it is not a conversion to a wider integer type of the same signedness, or (b) the expression is complex, or (c) the expression is not constant and is a function argument, or (d) the expression is not constant and is a return expression
  Misra2004:10.2 The value of an expression of floating type shall not be implicitly converted to a different type if: (a) it is not a conversion to a wider floating type, or (b) the expression is complex, or (c) the expression is a function argument, or (d) the expression is a return expression
AUTOSARC++14 AUTOSARC++14:A1-1-1 All code shall conform to ISO/IEC 14882:2014 - Programming Language C++ and shall not use deprecated features.
  AUTOSARC++14:M5-0-3 A cvalue expression shall not be implicitly converted to a different underlying type.
  AUTOSARC++14:M5-0-5 There shall be no implicit floating-integral conversions.
  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:5-0-3 A cvalue expression shall not be implicitly converted to a different underlying type.
  MisraC++2008:5-0-5 There shall be no implicit floating-integral conversions.
  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:4.1.2 Deprecated features should not be used
CERT-C CERT-C:FLP06-C Convert integers to floating point for floating-point operations
  CERT-C:STR04-C Use plain char for characters in the basic character set
JSF++ JSF++:162 Signed and unsigned values shall not be mixed in arithmetic or comparison operations.
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="Mismatched Operand Types"
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

unsigned int TYPE_MOT(signed int s, unsigned int u, char c){
    char mychar;
    unsigned int i=0;

    mychar = c + u;                                     /* exception case 1 */
    if (mychar > 'a'){
        mychar -= s;                                    /* exception case 2 */
    }

    if (mychar > 'a'){
        i = u + s;         /* 'Mismatched Operand Types' warning issued here */ 
    }    
    if (u < c){            /* 'Mismatched Operand Types' warning issued here */        
        i = u==5 ? c : s;  /* 'Mismatched Operand Types' warning issued here */ 
    }
    return i;
}

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/.