Misra: Added rule 15.6

This commit is contained in:
Daniel Marjamäki 2017-04-13 23:24:35 +02:00
parent ec72330e7a
commit 471a9af348
2 changed files with 29 additions and 0 deletions

View File

@ -101,3 +101,7 @@ int misra_15_5() {
return 2;
}
void misra_15_6() {
if (x!=0); // 15.6
}

View File

@ -369,6 +369,29 @@ def misra_15_5(data):
if token.str == 'return' and token.scope.type != 'Function':
reportError(token, 15, 5)
def misra_15_6(rawTokens):
state = 0
indent = 0
for token in rawTokens:
if token.str in ['if', 'for', 'while']:
state = 1
indent = 0
elif state == 1:
if token.str == '(':
indent = indent + 1
elif token.str == ')':
if indent == 0:
state = 0
elif indent == 1:
state = 2
indent = indent - 1
elif state == 2:
if token.str.startswith('//') or token.str.startswith('/*'):
continue
state = 0
if token.str != '{':
reportError(token, 15, 6)
for arg in sys.argv[1:]:
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
@ -401,5 +424,7 @@ for arg in sys.argv[1:]:
misra_15_2(cfg)
misra_15_3(cfg)
misra_15_5(cfg)
if cfgNumber == 1:
misra_15_6(data.rawTokens)