diff --git a/addons/misra.py b/addons/misra.py index 94c21727b..210b15723 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -2966,15 +2966,24 @@ class MisraChecker: STATE_OK = 2 # a case/default is allowed (we have seen 'break;'/'comment'/'{'/attribute) STATE_SWITCH = 3 # walking through switch statement scope + define = None state = STATE_NONE - end_swtich_token = None # end '}' for the switch scope + end_switch_token = None # end '}' for the switch scope for token in rawTokens: + if simpleMatch(token, '# define'): + define = token + if define: + if token.linenr != define.linenr: + define = None + else: + continue + # Find switch scope borders if token.str == 'switch': state = STATE_SWITCH if state == STATE_SWITCH: if token.str == '{': - end_swtich_token = findRawLink(token) + end_switch_token = findRawLink(token) else: continue @@ -2983,7 +2992,7 @@ class MisraChecker: elif token.str == ';': if state == STATE_BREAK: state = STATE_OK - elif token.next and token.next == end_swtich_token: + elif token.next and token.next == end_switch_token: self.reportError(token.next, 16, 3) else: state = STATE_NONE diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index e6a819b9c..7a4f777df 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -1555,6 +1555,8 @@ static void misra_16_3(void) { case 2: x++; } // 16.3 + + #define M_16_3(a,b,default) { (a), (b), (default) }, } static void misra_16_4(void) {