Skip to content

Commit 6e6296d

Browse files
authored
Fix #13648: False positive: Misra C 16.3: warn on default in pragma (danmar#7314)
1 parent bb787df commit 6e6296d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

addons/misra.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,15 +3157,15 @@ def misra_16_3(self, rawTokens):
31573157
STATE_OK = 2 # a case/default is allowed (we have seen 'break;'/'comment'/'{'/attribute)
31583158
STATE_SWITCH = 3 # walking through switch statement scope
31593159

3160-
define = None
3160+
directive = None
31613161
state = STATE_NONE
31623162
end_switch_token = None # end '}' for the switch scope
31633163
for token in rawTokens:
3164-
if simpleMatch(token, '# define'):
3165-
define = token
3166-
if define:
3167-
if token.linenr != define.linenr:
3168-
define = None
3164+
if simpleMatch(token, '# define') or simpleMatch(token, '# pragma'):
3165+
directive = token
3166+
if directive:
3167+
if token.linenr != directive.linenr:
3168+
directive = None
31693169
else:
31703170
continue
31713171

@@ -3231,7 +3231,7 @@ def misra_16_5(self, data):
32313231
for token in data.tokenlist:
32323232
if token.str != 'default':
32333233
continue
3234-
if token.previous and token.previous.str == '{':
3234+
if token.previous and (token.previous.str == '{'):
32353235
continue
32363236
tok2 = token
32373237
while tok2:

addons/test/misra/misra-test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// ~/cppcheck/cppcheck --dump misra/misra-test.h --std=c89
33
// ~/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
44

5+
#pragma ghs section rodata=default // no warning
6+
57
#include "path\file.h" // 20.2
68
#include "file//.h" // 20.2
79
#include "file/*.h" // 20.2

0 commit comments

Comments
 (0)