diff --git a/addons/misra.py b/addons/misra.py index bbf7e6c558e..53e497dc2ad 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -3157,15 +3157,15 @@ def misra_16_3(self, rawTokens): STATE_OK = 2 # a case/default is allowed (we have seen 'break;'/'comment'/'{'/attribute) STATE_SWITCH = 3 # walking through switch statement scope - define = None + directive = None state = STATE_NONE 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 + if simpleMatch(token, '# define') or simpleMatch(token, '# pragma'): + directive = token + if directive: + if token.linenr != directive.linenr: + directive = None else: continue @@ -3231,7 +3231,7 @@ def misra_16_5(self, data): for token in data.tokenlist: if token.str != 'default': continue - if token.previous and token.previous.str == '{': + if token.previous and (token.previous.str == '{'): continue tok2 = token while tok2: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 6e18e7610c5..b289b5c48de 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -2,6 +2,8 @@ // ~/cppcheck/cppcheck --dump misra/misra-test.h --std=c89 // ~/cppcheck/cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64 && python3 ../misra.py -verify misra/misra-test.c.dump +#pragma ghs section rodata=default // no warning + #include "path\file.h" // 20.2 #include "file//.h" // 20.2 #include "file/*.h" // 20.2