Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ def isFloatCounterInWhileLoop(whileToken):
lpar = whileToken.next
rpar = lpar.link
counterTokens = findCounterTokens(lpar.astOperand2)
tok_varid = tuple(tok.varId for tok in counterTokens if tok.varId)
whileBodyStart = None
if simpleMatch(rpar, ') {'):
whileBodyStart = rpar.next
Expand All @@ -840,13 +841,21 @@ def isFloatCounterInWhileLoop(whileToken):
token = whileBodyStart
while token != whileBodyStart.link:
token = token.next
for counterToken in counterTokens:
if not counterToken.valueType or not counterToken.valueType.isFloat():
continue
if token.isAssignmentOp and token.astOperand1.str == counterToken.str:
if not token.varId:
continue
if token.varId not in tok_varid:
continue
if not token.astParent or not token.valueType or not token.valueType.isFloat():
continue
parent = token.astParent
if parent.str in ('++', '--'):
return True
while parent:
if parent.isAssignmentOp and parent.str != "=" and parent.astOperand1 == token:
return True
if token.str == counterToken.str and token.astParent and token.astParent.str in ('++', '--'):
if parent.str == "=" and parent.astOperand1.str == token.str and parent.astOperand1 != token:
return True
parent = parent.astParent
return False


Expand Down
27 changes: 27 additions & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,34 @@ static void misra_14_1(void) {
} while ( a < 10.0f ); // no-warning

}
//13143
static bool misra_14_1_is_increasing (const double* const x, const size_t n)
{
double last = -INFINITY;
size_t i = ((size_t) 0);
while ((i < n) && isfinite(x[i]) && (x[i] > last)) { //no-warning for 14_1
last = x[i];
i++;
}
return i == n;
}

static void misra_14_1_compliant1_foo(float x){
int i = 0;
while(i < x){ // 10.4
i += x + x; // 10.3 10.4 no-warning for 14_1
}
}

static void misra_14_1_compliant2_foo(void){
int i = 0;
float f = 0f;
while (f < 10 && i < 10) { //10.4 12.1
float f = 0f;
f = f + i; // 10.3 10.4 no warning for 14_1
i++;
}
}
static void misra_14_2_init_value(int32_t *var) {
*var = 0;
}
Expand Down