![]() |
![]() |
2791 | ![]() |
||||
![]() | |||||||
| Shift operations | |||||||
A definite 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 always 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), behaviour is undefined. In the code below, the size of a
long is assumed to be 32 bits. If the value of si is less than 0 or greater than 31 the resulting behaviour is undefined.
/*PRQA S 1253,1277,1279,1575,1594,2017,2983,2986,3120,3198,3199,3203,3227,3408,4131 ++*/
void f1(unsigned long ul, int si)
{
if (si > 40)
{
ul = ul << si; /* 2791 */
}
}
void f2(unsigned long ul, int si)
{
if (si < 0)
{
ul = ul << si; /* 2791 */
}
}
MISRA C:2012 Rules applicable to message 2791:
| Dir-4.1 (Required) | Run-time failures shall be minimized |
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 |