![]() |
![]() |
2792 | ![]() |
||||
![]() | |||||||
| Shift operations | |||||||
An apparent anomaly has been detected. Examination of the context indicates that the value of the right hand operand (i.e. the number of bits to be shifted) is sometimes out of range. According to the ISO-C standard if the value is either negative or greater than or equal to the width in bits of the left hand operand (after integral promotion), behavior is undefined. In the code below, the size of a
long is assumed to be 32 bits. Unless the if statement is redundant, the code implies that the value of si is expected to exceed 40 sometimes - and if it does, behavior of the subsequent shift operation will be undefined.
/*PRQA S 1253,1277,1279,1575,1594,2017,2983,2986,3120,3198,3199,3203,3227,3408,4131 ++*/
void foo(unsigned long ul, int si)
{
if (si > 40)
{
}
ul = ul << si; /* 2792 */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |