From 06ef496dc7ab959939818c0482a4e6f9a5aae114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 14 Apr 2017 22:53:45 +0200 Subject: [PATCH] Misra: Add rule 21.3 --- addons/misra-test.c | 7 +++++++ addons/misra.py | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/misra-test.c b/addons/misra-test.c index ece5e4540..d14ae222f 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -199,3 +199,10 @@ union misra_19_2 { }; // 19.2 #define int short // 20.4 #undef X // 20.5 + +void misra_21_3() { + p1=malloc(10); // 21.3 + p2=calloc(10); // 21.3 + realloc(10); // 21.3 + free(p1); // 21.3 +} diff --git a/addons/misra.py b/addons/misra.py index 5cd3382ab..3cecdde80 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -112,8 +112,6 @@ def countSideEffects(expr): ret = 0 if expr.str in ['++', '--', '=']: ret = 1 - elif isFunctionCall(expr): - ret = 1 return ret + countSideEffects(expr.astOperand1) + countSideEffects(expr.astOperand2) def getForLoopExpressions(forToken): @@ -642,6 +640,11 @@ def misra_20_5(rawTokens): if simpleMatch(token, '# undef'): reportError(token, 20, 5) +def misra_21_3(data): + for token in data.tokenlist: + if (token.str in ['malloc', 'calloc', 'realloc', 'free']) and token.next and token.next.str == '(': + reportError(token, 21, 3) + if '-verify' in sys.argv[1:]: VERIFY = True @@ -713,6 +716,7 @@ for arg in sys.argv[1:]: misra_20_3(data.rawTokens) misra_20_4(data.rawTokens) misra_20_5(data.rawTokens) + misra_21_3(cfg) if VERIFY: for expected in VERIFY_EXPECTED: