[previous] MISRA C:2012  Rule-14.3:  (Required) [next] Controlling expressions shall not be invariant

Amplification:

This rule applies to:

Exception:

  1. Invariants that are used to create infinite loops are permitted.
  2. A do-while loop with an essentially Boolean controlling expression that evaluates to 0 is permitted.

Example Code:


#pragma PRQA_MESSAGES_OFF 2982

#include "misra.h"
#include "m3cmex.h"

extern int16_t rule_1403( void )
{
    int16_t loop = 1;

    while (loop != 0)                                           /* 2990           */
    {
        if (s16a > 10)
        {
            break;
        }
    }                                                           /* 2467           */

    if ((s16a < 10) || (s16a > 0))                              /* 2991 2995 2996 */
    {
    }

    if ((s16a < 10) && (s16a > 20))                             /* 2992      2996 */
    {
    }

    do
    {
        ++u16a;
    } while (u16a < 0u);                                        /* 2993      2996 */

    return 1;
}


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.



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