Misra: Refactoring with isFunctionCall

This commit is contained in:
Daniel Marjamäki 2017-04-15 15:20:28 +02:00
parent 20aa099d05
commit 485f8c0820
2 changed files with 15 additions and 9 deletions

View File

@ -1,7 +1,6 @@
// To test:
// ~/cppcheck/cppcheck --dump misra-test.c && python misra.py -verify misra-test.c.dump
#include <stdarg.h> // 17.1
#include "path\file.h" // 20.2
#include /*abc*/ "file.h" // 20.3
#include <setjmp.h> // 21.4
@ -180,6 +179,14 @@ void misra_16_7() {
}
}
void misra_17_1() {
va_list(); // 17.1
va_arg(); // 17.1
va_start(); // 17.1
va_end(); // 17.1
va_copy(); // 17.1
}
void misra_17_6(int x[static 20]) {} // 17.6
void misra_17_8(int x) {

View File

@ -536,10 +536,9 @@ def misra_16_7(data):
if simpleMatch(token, 'switch (') and isBoolExpression(token.next.astOperand2):
reportError(token, 16, 7)
def misra_17_1(rawTokens):
for token in rawTokens:
# TODO warn about va_list, etc
if simpleMatch(token, '# include <stdarg.h>'):
def misra_17_1(data):
for token in data.tokenlist:
if isFunctionCall(token) and token.astOperand1.str in ['va_list', 'va_arg', 'va_start', 'va_end' , 'va_copy']:
reportError(token, 17, 1)
def misra_17_6(rawTokens):
@ -633,7 +632,7 @@ def misra_20_5(data):
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 == '(':
if isFunctionCall(token) and (token.astOperand1.str in ['malloc', 'calloc', 'realloc', 'free']):
reportError(token, 21, 3)
def misra_21_4(data):
@ -648,12 +647,12 @@ def misra_21_5(data):
def misra_21_7(data):
for token in data.tokenlist:
if (token.str in ['atof', 'atoi', 'atol', 'atoll']) and token.next and token.next.str == '(':
if isFunctionCall(token) and (token.astOperand1.str in ['atof', 'atoi', 'atol', 'atoll']):
reportError(token, 21, 7)
def misra_21_8(data):
for token in data.tokenlist:
if (token.str in ['abort', 'getenv', 'system']) and token.next and token.next.str == '(':
if isFunctionCall(token) and (token.astOperand1.str in ['abort', 'getenv', 'system']):
reportError(token, 21, 8)
def misra_21_9(data):
@ -724,8 +723,8 @@ for arg in sys.argv[1:]:
misra_16_5(cfg)
misra_16_6(cfg)
misra_16_7(cfg)
misra_17_1(cfg)
if cfgNumber == 1:
misra_17_1(data.rawTokens)
misra_17_6(data.rawTokens)
misra_17_8(cfg)
misra_18_5(cfg)