Skip to content

Commit 55afaeb

Browse files
committed
Fixed #9506 (false positive: MISRA 12.4)
1 parent f5df06a commit 55afaeb

2 files changed

Lines changed: 2 additions & 10 deletions

File tree

addons/misra.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,7 @@ def isConstantExpression(expr):
345345

346346

347347
def isUnsignedInt(expr):
348-
# TODO this function is very incomplete. use ValueType?
349-
if not expr:
350-
return False
351-
if expr.isNumber:
352-
return 'u' in expr.str or 'U' in expr.str
353-
if expr.str in ('+', '-', '*', '/', '%'):
354-
return isUnsignedInt(expr.astOperand1) or isUnsignedInt(expr.astOperand2)
355-
return False
348+
return expr and expr.valueType and expr.valueType.type in ('short', 'int') and expr.valueType.sign == 'unsigned'
356349

357350

358351
def getPrecedence(expr):
@@ -1370,8 +1363,6 @@ def misra_12_4(self, data):
13701363
continue
13711364
if (not isConstantExpression(token)) or (not isUnsignedInt(token)):
13721365
continue
1373-
if not token.values:
1374-
continue
13751366
for value in token.values:
13761367
if value.intvalue < 0 or value.intvalue > max_uint:
13771368
self.reportError(token, 12, 4)

addons/test/misra/misra-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ void misra_12_4() {
367367
x = MISRA12_4a + MISRA12_4b; // 12.4
368368
x = 0u - 1u; // 12.4
369369
x = t ? 0u : (0u-1u); // 12.4
370+
x = 556200230913ULL;
370371
}
371372

372373
struct misra_13_1_t { int a; int b; };

0 commit comments

Comments
 (0)