From 76c3cef4d6188feac9ddc0a6a57ccb4b1ddca491 Mon Sep 17 00:00:00 2001 From: KMilhan Date: Thu, 26 Oct 2017 15:47:53 +0900 Subject: [PATCH] MISRA 15.7 only checks if...else if constructs (#983) --- addons/misra-test.c | 4 +++- addons/misra.py | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/misra-test.c b/addons/misra-test.c index 983b6d69f..528357caf 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -193,7 +193,9 @@ void misra_15_6() { } void misra_15_7() { - if (x!=0){} // 15.7 + if (x!=0){} // no-warning + if (x!=0){} else if(x==1){} // 15.7 + if (x!=0){} else if(x==1){}else{;} // no-warning } void misra_16_2() { diff --git a/addons/misra.py b/addons/misra.py index 4382027da..03583bced 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -773,11 +773,13 @@ def misra_15_6(rawTokens): def misra_15_7(data): for token in data.tokenlist: - if not simpleMatch(token, 'if ('): + if not simpleMatch(token, '}'): continue - if not simpleMatch(token.next.link, ') {'): + if not token.scope.type == 'If': continue - if not simpleMatch(token.next.link.next.link, '} else'): + if not token.scope.nestedIn.type == 'Else': + continue + if not token.next.str == 'else': reportError(token, 15, 7) # TODO add 16.1 rule