PREfast Warning 297 (Windows CE 5.0)
297 - Arithmetic overflow.
Additional Information: 32-bit value is shifted, then cast to 64-bit value.
Recommended Fix: Cast to a 64-bit value before the shift.
This warning indicates incorrect behavior resulting from integral promotion rules and types larger than those in which arithmetic is typically performed.
In this case, a 32-bit value was shifted left, and the result of that shift was cast to a 64-bit value. If the shift overflowed the 32-bit value, bits are lost.
If you do not want to lose bits, cast the value to be shifted to a 64-bit quantity before it is shifted.
If you want to loose bits, performing the appropriate cast (to unsigned long or a shorter type), or masking the result of the shift eliminates this warning and makes the intent of the code more clear.
Example
Defective Source
unsigned __int64 x;
x = i << 34;
Corrected Source
unsigned __int64 x;
x = ((unsigned __int64)i) << 34;
Send Feedback on this topic to the authors