...
The only integer type conversions that are guaranteed to be safe for all data values and all possible conforming implementations are conversions of an integral value to a wider type of the same signedness. C11, Section 6.3.1.3 [ISO/IEC 9899:2011], says,
When a value with integer type is converted to another integer type other than
_Bool
, if the value can be represented by the new type, it is unchanged.Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.
Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.
...
The CERT Oracle Secure Coding Standard for Java: NUM12-J. Ensure conversions of numeric types to narrower types do not result in lost or misinterpreted data
ISO/IEC 9899:2011 6 6.3, "Conversions"
ISO/IEC TR 24772 "FLC Numeric conversion errors"
...
MITRE CWE: CWE-192, "Integer coercion error," CWE-197, "Numeric truncation error," and CWE-681, "Incorrect conversion between numeric types"
...
[Dowd 2006] Chapter 6, "C Language Issues" ("Type conversions," pp. 223–270)
[Seacord 2005a] Chapter 5, "Integers"
[Viega 2005] Section 5.2.9, "Truncation error," Section 5.2.10, "Sign extension error," Section 5.2.11, "Signed to unsigned conversion error," and Section 5.2.12, "Unsigned to signed conversion error"
[Warren 2002] Chapter 2, "Basics"
[xorl 2009] "CVE-2009-1376: Pidgin MSN SLP Integer Truncationinteger truncation"
...