From 47126e93a4c0ff74207aab492c80120ea5236171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 14 Apr 2017 13:18:20 +0200 Subject: [PATCH] Misra: Added rule 16.6 --- addons/misra-test.c | 7 +++++++ addons/misra.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/addons/misra-test.c b/addons/misra-test.c index 561b65a15..7d828580d 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -157,4 +157,11 @@ void misra_16_5() { } } +void misra_16_6() { + switch (x) { // 16.6 + default: + break; + } +} + diff --git a/addons/misra.py b/addons/misra.py index a35ea2e60..e3d240bbf 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -475,6 +475,24 @@ def misra_16_5(data): if tok2 and tok2.str == 'case': reportError(token, 16, 5) +def misra_16_6(data): + for token in data.tokenlist: + if not (simpleMatch(token, 'switch (') and simpleMatch(token.next.link, ') {')): + continue + tok = token.next.link.next.next + count = 0 + while tok: + if tok.str == 'break': + count = count + 1 + elif tok.str == '{': + tok = tok.link + elif tok.str == '}': + break + tok = tok.next + if count < 2: + reportError(token, 16, 6) + + if '-verify' in sys.argv[1:]: VERIFY = True @@ -531,6 +549,7 @@ for arg in sys.argv[1:]: misra_16_3(data.rawTokens) misra_16_4(cfg) misra_16_5(cfg) + misra_16_6(cfg) if VERIFY: for expected in VERIFY_EXPECTED: