Misra: Added rule 17.1

This commit is contained in:
Daniel Marjamäki 2017-04-14 14:13:37 +02:00
parent e5286c61d5
commit 41e07c0614
3 changed files with 16 additions and 0 deletions

View File

@ -534,6 +534,11 @@ class CppcheckData:
tok = Token(node)
tok.file = files[int(node.get('fileIndex'))]
self.rawTokens.append(tok)
for i in range(len(self.rawTokens)):
if i > 0:
self.rawTokens[i].previous = self.rawTokens[i-1]
if i + 1 < len(self.rawTokens):
self.rawTokens[i].next = self.rawTokens[i+1]
# root is 'dumps' node, each config has its own 'dump' subnode.

View File

@ -1,6 +1,8 @@
// To test:
// ~/cppcheck/cppcheck --dump misra-test.c && python misra.py -verify misra-test.c.dump
#include <stdarg.h> // 17.1
typedef unsigned char u8;
void misra_5_1() {
@ -172,3 +174,5 @@ void misra_16_7() {
break;
}
}

View File

@ -497,6 +497,11 @@ 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:
if simpleMatch(token, '# include <stdarg.h>'):
reportError(token, 17, 1)
if '-verify' in sys.argv[1:]:
VERIFY = True
@ -556,6 +561,8 @@ for arg in sys.argv[1:]:
misra_16_5(cfg)
misra_16_6(cfg)
misra_16_7(cfg)
if cfgNumber == 1:
misra_17_1(data.rawTokens)
if VERIFY:
for expected in VERIFY_EXPECTED: