Skip to content

Commit

Permalink
Fix 11474: FP: misra-c2012-14.2 A for loop shall be well-formed
Browse files Browse the repository at this point in the history
  • Loading branch information
swasti16 committed Oct 20, 2023
1 parent b61feaf commit 67619bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,12 @@ def getForLoopCounterVariables(forToken):
vars_modified.add(tn.variable)
elif tn.previous and tn.previous.str in ('++', '--'):
vars_modified.add(tn.variable)
if cur_clause == 1 and tn.isAssignmentOp and tn.astOperand1.variable:
vars_initialized.add(tn.astOperand1.variable)
if cur_clause == 1 and tn.isAssignmentOp:
if tn.astOperand1.variable:
vars_initialized.add(tn.astOperand1.variable)
elif tn.astOperand1.str == "." and tn.astOperand1.astOperand2 and tn.astOperand1.astOperand2.variable:
vars_initialized.add(tn.astOperand1.astOperand2.variable)

if tn.str == ';':
cur_clause += 1
tn = tn.next
Expand Down
8 changes: 8 additions & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,14 @@ static void misra_14_2_fn1(bool b) {
}
}
}

static struct
{
uint16_t block;
bool readSuccessful;
}
opState;
for (opState.block = 0U; opState.block < 10U; opState.block++) {;} //no-warning
}
static void misra_14_2_fn2(void)
{
Expand Down

0 comments on commit 67619bd

Please sign in to comment.