From c56926f4bd9d238f410d0737ae88324d10d2ef0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Apr 2017 12:48:28 +0200 Subject: [PATCH] Misra: Add rule 5.5 --- addons/misra-test.c | 3 +++ addons/misra.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/addons/misra-test.c b/addons/misra-test.c index c8470684f..332813095 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -17,6 +17,9 @@ void misra_5_1() { int a1234567890123456789012345678901; // 5.1 } +#define m55(x,y) (x+y) +int m55; // 5.5 + void misra_7_1() { int x = 066; // 7.1 } diff --git a/addons/misra.py b/addons/misra.py index 6a03bf3c7..2b26afda7 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -273,6 +273,16 @@ def misra_5_1(data): if token.isName and len(token.str) > 31: reportError(token, 5, 1) +def misra_5_5(data): + macroNames = [] + for dir in data.directives: + res = re.match(r'#define ([A-Za-z0-9_]+)', dir.str) + if res: + macroNames.append(res.group(1)) + for var in data.variables: + if var.nameToken.str in macroNames: + reportError(var.nameToken, 5, 5) + def misra_7_1(rawTokens): for tok in rawTokens: if re.match(r'^0[0-7]+$', tok.str): @@ -949,6 +959,7 @@ for arg in sys.argv[1:]: print('Checking ' + arg + ', config "' + cfg.name + '"...') misra_5_1(cfg) + misra_5_5(cfg) if cfgNumber == 1: misra_7_1(data.rawTokens) misra_7_3(data.rawTokens)