Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

CERT C++ Secure Coding StandardINT02-CPP. Understand integer conversion rules
ISO/IEC TR 24772Numeric conversion errors [FLC]
MISRA-CRule 10.1 (required): 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
Rule 10.3 (required): The value of a complex expression of integer type may only be cast to a type that is narrower and of the same
   signedness as the underlying type of the expression
Rule 10.5 (required): If the bitwise operators ~ and << are applied to an operand of underlying type unsigned char or unsigned short,
   the result shall be immediately cast to the underlying type of the operand
Rule 12.9 (required): The unary minus operator shall not be applied to an expression whose underlying type is unsigned

MITRE CWECWE-192, Integer coercion error
CWE-197, Numeric truncation error

Bibliography

[Dowd 2006]Chapter 6, "C Language Issues" ("Type Conversions," pp. 223–270)
[ISO/IEC 9899:2011]

Section 6.3.1.1, "Boolean, Characters, and Integers"
Section 6.3.1.3, "Signed and Unsigned Integers"

[Seacord 2005a]Chapter 5, "Integers"

...