Misra: Add rule 18.8

This commit is contained in:
Daniel Marjamäki 2017-04-14 21:09:25 +02:00
parent 8c42e052ac
commit e3872f9718
2 changed files with 19 additions and 0 deletions

View File

@ -184,3 +184,9 @@ void misra_17_8(int x) {
void misra_18_5() {
int *** p; // 18.5
}
void misra_18_8(int x) {
int buf1[10];
int buf2[sizeof(int)];
int vla[x]; // 18.8
}

View File

@ -122,6 +122,8 @@ def isConstantExpression(expr):
return True
if expr.isName:
return False
if simpleMatch(expr.previous, 'sizeof ('):
return True
if expr.astOperand1 and not isConstantExpression(expr.astOperand1):
return False
if expr.astOperand2 and not isConstantExpression(expr.astOperand2):
@ -532,6 +534,16 @@ def misra_18_5(data):
if count > 2:
reportError(var.nameToken, 18, 5)
def misra_18_8(data):
for var in data.variables:
if not var.isArray:
continue
# TODO Array dimensions are not available in dump
typetok = var.nameToken.next
if not typetok or typetok.str != '[':
continue
if not isConstantExpression(typetok.astOperand2):
reportError(var.nameToken, 18, 8)
if '-verify' in sys.argv[1:]:
VERIFY = True
@ -596,6 +608,7 @@ for arg in sys.argv[1:]:
misra_17_6(data.rawTokens)
misra_17_8(cfg)
misra_18_5(cfg)
misra_18_8(cfg)
if VERIFY:
for expected in VERIFY_EXPECTED: