diff --git a/addons/misra.py b/addons/misra.py index 289d6ad46..39be7af8e 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -808,17 +808,31 @@ def misra_10_8(data): continue if not token.astOperand1.astOperand1: continue - try: - intTypes = ['char', 'short', 'int', 'long', 'long long'] - index1 = intTypes.index(token.valueType.type) - e = getEssentialType(token.astOperand1) - if not e: + if token.astOperand1.str not in {'+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":", '~'}: + continue + if token.astOperand1.str != '~' and not token.astOperand1.astOperand2: + continue + if token.astOperand1.str == '~': + e2 = getEssentialTypeCategory(token.astOperand1.astOperand1) + else: + e2, e3 = getEssentialCategorylist(token.astOperand1.astOperand1, token.astOperand1.astOperand2) + if e2 != e3: continue - index2 = intTypes.index(e) - if index1 > index2: - reportError(token, 10, 8) - except ValueError: - pass + e1 = getEssentialTypeCategory(token) + if e1 != e2: + reportError(token, 10, 8) + else: + try: + intTypes = ['char', 'short', 'int', 'long', 'long long'] + index1 = intTypes.index(token.valueType.type) + e = getEssentialType(token.astOperand1) + if not e: + continue + index2 = intTypes.index(e) + if index1 > index2: + reportError(token, 10, 8) + except ValueError: + pass def misra_11_3(data): diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index 963276430..2c170121a 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -168,9 +168,10 @@ void misra_10_6(u8 x, u32 a, u32 b) { u32 c = ( u16) ( u32 a + u32 b ); //10.6 } -void misra_10_8(u8 x) { +void misra_10_8(u8 x, s32 a, s32 b) { y = (u16)x; y = (u16)(x+x); // 10.8 + y = (u16) (a + b) //10.8 } struct Fred {}; struct Wilma {};