Fixed #9506 (false positive: MISRA 12.4)

This commit is contained in:
Daniel Marjamäki 2019-12-08 18:52:52 +01:00
parent f5df06a143
commit 55afaebdac
2 changed files with 2 additions and 10 deletions

View File

@ -345,14 +345,7 @@ def isConstantExpression(expr):
def isUnsignedInt(expr): def isUnsignedInt(expr):
# TODO this function is very incomplete. use ValueType? return expr and expr.valueType and expr.valueType.type in ('short', 'int') and expr.valueType.sign == 'unsigned'
if not expr:
return False
if expr.isNumber:
return 'u' in expr.str or 'U' in expr.str
if expr.str in ('+', '-', '*', '/', '%'):
return isUnsignedInt(expr.astOperand1) or isUnsignedInt(expr.astOperand2)
return False
def getPrecedence(expr): def getPrecedence(expr):
@ -1370,8 +1363,6 @@ class MisraChecker:
continue continue
if (not isConstantExpression(token)) or (not isUnsignedInt(token)): if (not isConstantExpression(token)) or (not isUnsignedInt(token)):
continue continue
if not token.values:
continue
for value in token.values: for value in token.values:
if value.intvalue < 0 or value.intvalue > max_uint: if value.intvalue < 0 or value.intvalue > max_uint:
self.reportError(token, 12, 4) self.reportError(token, 12, 4)

View File

@ -367,6 +367,7 @@ void misra_12_4() {
x = MISRA12_4a + MISRA12_4b; // 12.4 x = MISRA12_4a + MISRA12_4b; // 12.4
x = 0u - 1u; // 12.4 x = 0u - 1u; // 12.4
x = t ? 0u : (0u-1u); // 12.4 x = t ? 0u : (0u-1u); // 12.4
x = 556200230913ULL;
} }
struct misra_13_1_t { int a; int b; }; struct misra_13_1_t { int a; int b; };