[previous] 2872 [next] This loop, if entered, will never terminate.
Control flow

If this loop is entered it will never terminate.

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 */
    {

    }
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents