From f6afbbe65d0edbbbf6a61eff5062404377d05e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 12 Apr 2017 16:19:13 +0200 Subject: [PATCH] Misra: updated 12.1 check --- addons/misra-test.c | 2 +- addons/misra.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/addons/misra-test.c b/addons/misra-test.c index 7e9ee7e0c..07ba8b907 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -17,7 +17,7 @@ void misra_7_3() { } void misra_12_1() { -// TODO sz = sizeof x + y; // 12.1 + sz = sizeof x + y; // 12.1 a = (b * c) + d; a = b << c + d; // 12.1 } diff --git a/addons/misra.py b/addons/misra.py index acf6f7b7d..7e6294e2f 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -86,6 +86,24 @@ def misra_7_3(rawTokens): reportError(tok, 7, 3) +def misra_12_1_sizeof(rawTokens): + state = 0 + for tok in rawTokens: + if tok.str.startswith('//') or tok.str.startswith('/*'): + continue + if tok.str == 'sizeof': + state = 1 + elif state == 1: + if re.match(r'^[a-zA-Z_]',tok.str): + state = 2 + else: + state = 0 + elif state == 2: + if tok.str in ['+','-','*','/','%']: + reportError(tok, 12, 1) + else: + state = 0 + def misra_12_1(data): for token in data.tokenlist: p = getPrecedence(token) @@ -136,6 +154,7 @@ for arg in sys.argv[1:]: if cfgNumber == 1: misra_7_1(data.rawTokens) misra_7_3(data.rawTokens) + misra_12_1_sizeof(data.rawTokens) misra_12_1(cfg) misra_13_5(cfg) misra_14_4(cfg)