Misra: Add rule 15.5

This commit is contained in:
Daniel Marjamäki 2017-04-13 23:07:41 +02:00
parent 4ebe520858
commit ec72330e7a
2 changed files with 14 additions and 0 deletions

View File

@ -93,3 +93,11 @@ void misra_15_3() {
} }
} }
} }
int misra_15_5() {
if (x!=0) {
return 1; // 15.5
}
return 2;
}

View File

@ -364,6 +364,11 @@ def misra_15_3(data):
if not scope: if not scope:
reportError(token, 15, 3) reportError(token, 15, 3)
def misra_15_5(data):
for token in data.tokenlist:
if token.str == 'return' and token.scope.type != 'Function':
reportError(token, 15, 5)
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
print('Checking ' + arg + '...') print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg) data = cppcheckdata.parsedump(arg)
@ -395,5 +400,6 @@ for arg in sys.argv[1:]:
misra_15_1(cfg) misra_15_1(cfg)
misra_15_2(cfg) misra_15_2(cfg)
misra_15_3(cfg) misra_15_3(cfg)
misra_15_5(cfg)