![]() |
![]() |
2863 | ![]() |
||||
![]() | |||||||
| Shift operations | |||||||
Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable. A left shift operation is being performed on a signed integer expression and examination of the immediate context suggests that the result of this operation could sometimes be implementation-defined. The result of a left shift operation will probably be meaningless when the value of the left hand operand is negative or when it is positive and of a magnitude such that the sign bit may be set by the shift operation. This will happen in the example below unless the parameter 'n' is greater than 0.
/*PRQA S 295,502,1253,1277,1279,2017,2982,2983,2984,2986,3120,3198,3199,3203,3227,3408,4131 ++*/
void foo(int n)
{
long sl = 0x10000000L;
long slr;
int i;
for (i = 0; i < n; ++i)
{
sl = sl >> 1;
}
slr = sl << 2; /* */
slr = sl << 3; /* 2863 */
slr = sl << 4; /* 2863 */
}
No MISRA C:2012 Rules applicable to message 2863
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |