From 55afaebdac5dcbeec01cd9ad159332e18bfe6e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 Dec 2019 18:52:52 +0100 Subject: [PATCH] Fixed #9506 (false positive: MISRA 12.4) --- addons/misra.py | 11 +---------- addons/test/misra/misra-test.c | 1 + 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index 347b6d5fc..469f8abdf 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -345,14 +345,7 @@ def isConstantExpression(expr): def isUnsignedInt(expr): - # TODO this function is very incomplete. use ValueType? - 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 + return expr and expr.valueType and expr.valueType.type in ('short', 'int') and expr.valueType.sign == 'unsigned' def getPrecedence(expr): @@ -1370,8 +1363,6 @@ class MisraChecker: continue if (not isConstantExpression(token)) or (not isUnsignedInt(token)): continue - if not token.values: - continue for value in token.values: if value.intvalue < 0 or value.intvalue > max_uint: self.reportError(token, 12, 4) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 7cb175ef7..88c673f50 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -367,6 +367,7 @@ void misra_12_4() { x = MISRA12_4a + MISRA12_4b; // 12.4 x = 0u - 1u; // 12.4 x = t ? 0u : (0u-1u); // 12.4 + x = 556200230913ULL; } struct misra_13_1_t { int a; int b; };