Misra: Add rule 15.7

This commit is contained in:
Daniel Marjamäki 2017-04-14 08:05:14 +02:00
parent 471a9af348
commit 0052ef7437
2 changed files with 34 additions and 5 deletions

View File

@ -50,10 +50,12 @@ void misra_13_3() {
void misra_13_4() {
if (x != (y = z)) {} // 13.4
else {}
}
void misra_13_5() {
if (x && (y++ < 123)){} // 13.5
else {}
}
void misra_13_6() {
@ -73,6 +75,7 @@ void misra_14_2() {
void misra_14_4() {
if (x+4){} // 14.4
else {}
}
void misra_15_1() {
@ -90,18 +93,23 @@ void misra_15_3() {
goto L1; // 15.3 15.1
if (y!=0) {
L1:
}
}
} else {}
} else {}
}
int misra_15_5() {
if (x!=0) {
return 1; // 15.5
}
} else {}
return 2;
}
void misra_15_6() {
if (x!=0); // 15.6
else{}
}
void misra_15_7() {
if (x!=0){} // 15.7
}

View File

@ -392,6 +392,27 @@ def misra_15_6(rawTokens):
if token.str != '{':
reportError(token, 15, 6)
def misra_15_7(data):
for token in data.tokenlist:
if token.str != 'if':
continue
lpar = token.next
if not lpar or lpar.str != '(':
continue
rpar = lpar.link
if not rpar or rpar.str != ')':
continue
brace1 = rpar.next
if not brace1 or brace1.str != '{':
continue
brace2 = brace1.link
if not brace2 or brace2.str != '}':
continue
else_ = brace2.next
if not else_ or else_.str != 'else':
reportError(token, 15, 7)
for arg in sys.argv[1:]:
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
@ -426,5 +447,5 @@ for arg in sys.argv[1:]:
misra_15_5(cfg)
if cfgNumber == 1:
misra_15_6(data.rawTokens)
misra_15_7(cfg)