[previous] MISRA-C:2004  Rule  13.7:  (Required) [next] Boolean operations whose results are invariant shall not be permitted.
If a Boolean operator yields a result that can be proven to be always "true" or always "false", it is highly likely that there is a programming error.

enum ec {RED, BLUE, GREEN} col;
...
if ( u16a < 0 )             /* Not compliant - u16a is always >= 0 */
...
if ( u16a <= 0xffff )               /* Not compliant - always true */
...
if ( s8a < 130 )                    /* Not compliant - always true */
...
if ( ( s8a < 10 ) && ( s8a > 20 ) ) /* Not compliant - always false */
...
if ( ( s8a < 10 ) || ( s8a > 5 ) )  /* Not compliant - always true */
...
if ( col <= GREEN )                 /* Not compliant - always true */
...
if ( s8a > 10 )
{
    if ( s8a > 5 )          /* Not compliant - s8a is not volatile */
    {
    }
}


QAC messages that encompass this guideline:

2990 The value of this loop controlling expression is always 'true'.
2991 The value of this 'if' controlling expression is always 'true'.
2992 The value of this 'if' controlling expression is always 'false'.
2993 The value of this 'do - while' loop controlling expression is always 'false'. The loop will only be executed once.
2994 The value of this 'while' or 'for' loop controlling expression is always 'false'. The loop will not be entered.
2995 The result of this logical operation is always 'true'.
2996 The result of this logical operation is always 'false'.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents