From 471a9af3487fa1c99a473d9d3d6a08b92ce4c209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 13 Apr 2017 23:24:35 +0200 Subject: [PATCH] Misra: Added rule 15.6 --- addons/misra-test.c | 4 ++++ addons/misra.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/addons/misra-test.c b/addons/misra-test.c index f40c43647..068e7fe4c 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -101,3 +101,7 @@ int misra_15_5() { return 2; } + +void misra_15_6() { + if (x!=0); // 15.6 +} diff --git a/addons/misra.py b/addons/misra.py index e9065394c..772a1e1ca 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -369,6 +369,29 @@ def misra_15_5(data): if token.str == 'return' and token.scope.type != 'Function': reportError(token, 15, 5) +def misra_15_6(rawTokens): + state = 0 + indent = 0 + for token in rawTokens: + if token.str in ['if', 'for', 'while']: + state = 1 + indent = 0 + elif state == 1: + if token.str == '(': + indent = indent + 1 + elif token.str == ')': + if indent == 0: + state = 0 + elif indent == 1: + state = 2 + indent = indent - 1 + elif state == 2: + if token.str.startswith('//') or token.str.startswith('/*'): + continue + state = 0 + if token.str != '{': + reportError(token, 15, 6) + for arg in sys.argv[1:]: print('Checking ' + arg + '...') data = cppcheckdata.parsedump(arg) @@ -401,5 +424,7 @@ for arg in sys.argv[1:]: misra_15_2(cfg) misra_15_3(cfg) misra_15_5(cfg) + if cfgNumber == 1: + misra_15_6(data.rawTokens)