![]() |
![]() |
2468 | ![]() |
||||
![]() | |||||||
| Control flow | |||||||
The control variable in this loop construct is never modified within the visible code of the loop. Is this intended ? The variable is declared at file scope and so, perhaps it is being modified via a function call ? QAC attempts to identify a loop control variable when analysing for loops and while loops. 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 loop, it is not obvious that the loop control variable is ever modified either in the control statement or in the body of the loop. If it is not modified via a function call or through a pointer, the loop could execute indefinitely. For example:
/*PRQA S 1-9999 ++*/
/*PRQA S 2461, 2467, 2468, 2990 --*/
extern int fen;
static int fsn;
extern void f1(void)
{
int lan;
for (fen = 0; fen < 10; ++fen) { } /* 2461 */
for (fsn = 0; fsn < 10; ++fsn) { } /* 2461 */
for (lan = 0; lan < 10; ++lan) { } /* */
for (fen = 0; fen < 10; ) { } /* 2461 2468 2990 */
for (fsn = 0; fsn < 10; ) { } /* 2461 2468 2880 */
for (lan = 0; lan < 10; ) { } /* 2467 */
}
No MISRA C:2012 Rules applicable to message 2468
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 |