Fixed #10853 (False positive: misra-c2012-16.3: macro parameter "default")

This commit is contained in:
Daniel Marjamäki 2022-03-13 19:58:15 +01:00
parent 2eed660b32
commit a6c1653ed2
2 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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) {