...
If an integer operator other than a shift operator has at least one operand of type
long, then the operation is carried out using 64-bit precision, and the result of the numerical operator is of typelong. If the other operand is notlong, it is first widened (§5§5.1.5) to typelongby numeric promotion (§5§5.6). Otherwise, the operation is carried out using 32-bit precision, and the result of the numerical operator is of typeint. If either operand is not anint, it is first widened to typeintby numeric promotion.
...
| Code Block | ||
|---|---|---|
| ||
int result = 0;
for(int i = 0; i < 4; i++)
result = ((result << 8) | (b[i] & 0xff));
|
Risk Assessment
Failing to consider integer promotions when dealing with floating point and integer operands can result in loss of precision.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
| Wiki Markup |
|---|
\[[JLS 05|AA. Java References#JLS 05]\] 4.2.2 "Integer Operations" and 5.6 "Numeric Promotions" \[[Findbugs 08|AA. Java References#Findbugs 08]\] "BIT: Bitwise OR of signed byte value" |
...