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.INA : Inappropriate Numeric Assignment

Summary

FIXME

Properties

Class Name Inappropriate Numeric Assignment
Significance style
Mnemonic LANG.TYPE.INA
Categories
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: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-6 An implicit integral or floating-point conversion shall not reduce the size of the underlying type.
  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-6 An implicit integral or floating-point conversion shall not reduce the size of the underlying type.
  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.6 Assignment between numeric types shall be appropriate
CERT-C CERT-C:FLP34-C Ensure that floating-point conversions are within range of the new type
  CERT-C:FLP36-C Preserve precision when converting integral values to floating-point type
  CERT-C:STR04-C Use plain char for characters in the basic character set
JSF++ JSF++:180 Implicit conversions that may result in a loss of information shall not be used.
  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.
Availability Available for C++ only (not 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 Numeric Assignment"
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 char u8;

enum Colour : unsigned short { red, green, blue } c;

void TYPE_INA(unsigned long long lli)
{
  u8 = lli; /* 'Inappropriate Numeric Assignment' warning issued here */
  u8 = c;   /* 'Inappropriate Numeric Assignment' warning issued here */
}

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