Converting from one data type to another, such as long to integer, data can be omitted or translated in a way that produces unexpected values. If the resulting values are used in a sensitive context, then dangerous behaviors may occur.
1
2void incorrectConversionOfNumericTypesNoncompliant(int int_var) {
3 // Noncompliant: A primitive is cast to a primitive of a smaller size.
4 char char_var = int_var;
5}
1
2void incorrectConversionOfNumericTypesCompliant(int int_var) {
3 // Compliant: A primitive is cast to a primitive of a same size.
4 int char_var = int_var;
5}