Misra: Add rule 21.3

This commit is contained in:
Daniel Marjamäki 2017-04-14 22:53:45 +02:00
parent 8a614ed188
commit 06ef496dc7
2 changed files with 13 additions and 2 deletions

View File

@ -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
}

View File

@ -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: