![]() |
![]() |
2923 | ![]() |
||||
![]() | |||||||
| Shift operations | |||||||
Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable. An expression of unsigned type is the subject of a left shift operation and examination of the immediate context suggests that high order bits could sometimes be lost. Is this intended ? This will happen in the example below unless the parameter 'n' is greater than 0.
/*PRQA S 1278,2017,2983,2986,3120,3199,3227,3381,3408 ++*/
/*******************************/
/* OPTIONS: -s int=16 */
/*******************************/
void foo(int n)
{
unsigned int un = 4096U;
int i;
for (i = 0; i < n; ++i)
{
un = un - 1U;
}
un = un << 4; /* 2923 */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |