misra.py: Fix crash on volatile macro argument (#2654)

This commit is contained in:
Georgy Komarov 2020-05-21 09:34:28 +03:00 committed by GitHub
parent 9861a5291e
commit 90550d24c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -1735,6 +1735,8 @@ class MisraChecker:
if (not isConstantExpression(token)) or (not isUnsignedInt(token)):
continue
for value in token.values:
if value.intvalue is None:
continue
if value.intvalue < 0 or value.intvalue > max_uint:
self.reportError(token, 12, 4)
break

View File

@ -473,6 +473,7 @@ void misra_12_3(int a, int b, int c) { // no warning
#define MISRA12_4a 2000000000u
#define MISRA12_4b 4000000000u
#define volatile_macro_12_4 (*(volatile U32 *) 0xFFFFFC10u)
void misra_12_4() {
uint32_t x;
bool t;
@ -481,6 +482,7 @@ void misra_12_4() {
x = 0u - 1u; // 12.4
x = t ? 0u : (0u-1u); // 12.4
x = 556200230913ULL;
foo(&volatile_macro_12_4); // no crash
}
struct misra_13_1_t { int a; int b; };