cert.py: fixed fp in exp05 for non-pointer casts

This commit is contained in:
Daniel Marjamäki 2018-04-03 15:12:01 +02:00
parent d31ba0ca02
commit 97b17d50aa
2 changed files with 12 additions and 1 deletions

View File

@ -88,13 +88,18 @@ def getArguments(ftok):
# EXP05-C # EXP05-C
# do not attempt to cast away const # do not attempt to cast away const
def exp05(data): def exp05(data):
# TODO Reuse code in misra rule 11.8
for token in data.tokenlist: for token in data.tokenlist:
if isCast(token): if isCast(token):
# C-style cast # C-style cast
if not token.valueType: if not token.valueType:
continue continue
if not token.astOperand1.valueType: if not token.astOperand1.valueType:
continue continue
if token.valueType.pointer == 0:
continue
if token.astOperand1.valueType.pointer == 0:
continue
const1 = token.valueType.constness const1 = token.valueType.constness
const2 = token.astOperand1.valueType.constness const2 = token.astOperand1.valueType.constness
if (const1 % 2) < (const2 % 2): if (const1 % 2) < (const2 % 2):
@ -106,9 +111,13 @@ def exp05(data):
for argnr, argvar in function.argument.items(): for argnr, argvar in function.argument.items():
if argnr < 1 or argnr > len(arguments): if argnr < 1 or argnr > len(arguments):
continue continue
if not argvar.isPointer:
continue
argtok = arguments[argnr - 1] argtok = arguments[argnr - 1]
if not argtok.valueType: if not argtok.valueType:
continue continue
if argtok.valueType.pointer == 0:
continue
const1 = argvar.isConst const1 = argvar.isConst
const2 = arguments[argnr - 1].valueType.constness const2 = arguments[argnr - 1].valueType.constness
if (const1 % 2) < (const2 % 2): if (const1 % 2) < (const2 % 2):

View File

@ -17,6 +17,8 @@ void dostuff(int *data);
void exp05() void exp05()
{ {
const int x = 42; const int x = 42;
int y = (int)x;
int *p; int *p;
p = (int *)&x; // cert-EXP05-C p = (int *)&x; // cert-EXP05-C