From 90a2a46959eeb7a4a27beefcafa66284510f4f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 1 Oct 2018 20:16:48 +0200 Subject: [PATCH] Fixed #8657 (false postive: MISRA rule 15.7) --- addons/misra.py | 14 ++++++++------ addons/test/misra-test.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) 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() {