From aa2d1fd6833ff9e0974482e89f14d246adeef853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 14 Apr 2017 08:17:32 +0200 Subject: [PATCH] Misra: Add rule 16.2 --- addons/misra-test.c | 9 +++++++++ addons/misra.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/addons/misra-test.c b/addons/misra-test.c index b908bb2b6..fc9075538 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -113,3 +113,12 @@ void misra_15_7() { if (x!=0){} // 15.7 } +void misra_16_2() { + switch (x) { + case 1: + while (y>4) { + case 2: break; // 16.2 + } + break; + } +} diff --git a/addons/misra.py b/addons/misra.py index c7c0a373c..fbe5dbac7 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -412,6 +412,12 @@ def misra_15_7(data): if not else_ or else_.str != 'else': reportError(token, 15, 7) +# TODO add 16.1 rule + +def misra_16_2(data): + for token in data.tokenlist: + if token.str == 'case' and token.scope.type != 'Switch': + reportError(token, 16, 2) for arg in sys.argv[1:]: print('Checking ' + arg + '...') @@ -448,4 +454,5 @@ for arg in sys.argv[1:]: if cfgNumber == 1: misra_15_6(data.rawTokens) misra_15_7(cfg) + misra_16_2(cfg)