[previous] 2993 [next] The value of this 'do - while' loop controlling expression is always 'false'. The loop will only be executed once.
Invariant operations

The controlling expression in this 'do .. while' statement will always evaluate to zero and so the loop will therefore only be executed once. This suggests a logical flaw in the code. If this is really the intended behaviour, there are more transparent ways of achieving the same effect - e.g. by replacing the controlling expression with the value 0.

For example:


/*PRQA S 2017,3204,3227,3356,3360,3408 ++*/
void foo(int i)
{
    if (i == 0)
    {
        do
        {
        } while (i != 0);                /* 2993 2996 */
    }
}


MISRA C:2012 Rules applicable to message 2993:

Rule-14.3  (Required) Controlling expressions shall not be invariant


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