[previous] 2470 [next] Taking address of loop control variable, %s.
Control flow

The address of the loop control variable in this loop construct is being used.

QAC attempts to identify a loop control variable when analysing for loops and whileloops. Sometimes this is not possible because the concept of a loop control variable is not an intrinsic feature of the C language and loop control may depend on more than one variable. However in most situations, control of a loop is associated with a single local variable and it is important that modification of its value is clearly understood.

In this case, by taking the address of the loop control variable, it is possible that its value may be modified through a pointer alias. This could be confusing and dangerous.

For example:


/*PRQA S 2017,2211,2469,3198,3203,3227,3408,3447 ++*/

extern void mix(int *p);

extern void f1(int n)
{
    int i;

    for (i = 0; i > n; ++i)
    {
        mix(&i);                                /* Message 2470 */
    }
}


No MISRA-C:2004 Rules applicable to message 2470


QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents