![]() |
![]() |
2861 | ![]() |
||||
![]() | |||||||
| Shift operations | |||||||
A definite anomaly has been detected. The value of an expression of signed type is the subject of a left shift operation. Examination of the context indicates that the value being shifted will always be either negative or else of a positive value of magnitude such that the sign bit may be set. In either case the resulting value will be implementation-defined. In general, shift operations on expressions of signed type should be avoided. In the code below, the size of a long is assumed to be 32 bits. If the value of
sl is greater than or equal to 0x10000000L, any operation which shifts left by more than 2 bits may generate a result which is negative.
/*PRQA S 294,1253,1277,1279,2017,2982,2983,2984,2986,3120,3198,3199,3203,3227,3408,4131 ++*/
void foo(long sl)
{
long slr;
if (sl > 0x0fffffffL)
{
slr = sl << 2; /* */
slr = sl << 3; /* 2861 */
slr = sl << 4; /* 2861 */
}
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |