diff --git a/addons/misra.py b/addons/misra.py index 5aad72881..1951d80a0 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1326,15 +1326,17 @@ class MisraChecker: def misra_15_7(self, data): - for token in data.tokenlist: - if not simpleMatch(token, '}'): + for scope in data.scopes: + if scope.type != 'Else': continue - if not token.scope.type == 'If': + if not simpleMatch(scope.bodyStart, '{ if ('): continue - if not token.scope.nestedIn.type == 'Else': + tok = scope.bodyStart.next.next.link + if not simpleMatch(tok, ') {'): continue - if not token.next.str == 'else': - self.reportError(token, 15, 7) + tok = tok.next.link + if not simpleMatch(tok, '} else'): + self.reportError(tok, 15, 7) # TODO add 16.1 rule diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index a3665f1a5..e80ac1caf 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -353,9 +353,25 @@ void misra_15_6() { } void misra_15_7() { + uint32_t var = 0; + uint32_t var2 = 0; + if (x!=0){} // no-warning if (x!=0){} else if(x==1){} // 15.7 if (x!=0){} else if(x==1){}else{;} // no-warning + + if (x!=0) + { + } + else + { + var = 5u; + + if (var != 5u) + { + var2 = 10u; + } // no-warning + } } void misra_16_2() {