[previous] 2871 [next] Infinite loop identified.
Control flow

An infinite loop has been detected. This doesn't appear to be deliberate because the loop control expression is not a constant expression.

Consider the two loop constructs shown below.

1) In the first example, the loop is always entered and is always infinite. Message 2871 is generated for this case.

2) In the second example, execution of the loop depends on the value of the function parameter "n". If "n" is greater than 10, the loop will not be entered; but if it is entered, the loop will never terminate. Message 2872 is generated for this case.


/*PRQA S 2017,2467,3120,3204,3227,3408 ++*/

void f1(void)
{
    int i;
    int n = 5;

    for (i = 0; i < n;    )     	/* 2871 */
    {

    }
}

void f2(int n)
{
    while (n <= 10)              	/* 2872 */
    {

    }
}


MISRA C:2012 Rules applicable to message 2871:

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