misra.py: Fix 20.7 false positive for multi-character arguments

See: https://trac.cppcheck.net/ticket/9633#comment:3
This commit is contained in:
Georgy Komarov 2020-08-08 13:03:19 +03:00
parent b263b93f73
commit 3bae716fd4
No known key found for this signature in database
GPG Key ID: 195B8622FE88ED46
2 changed files with 14 additions and 5 deletions

View File

@ -2320,11 +2320,16 @@ class MisraChecker:
else:
state_in_string = True
pos_search += 1
elif exp[pos_search] in directive_args:
skip_next = True # Skip check for the next argument
break
elif exp[pos_search] == arg:
pos_search += 1
elif exp[pos_search].isalnum():
word = ""
while pos_search < len(exp) and exp[pos_search].isalnum():
word += exp[pos_search]
pos_search += 1
if word == arg:
pos_search += 1
elif word in directive_args:
skip_next = True
break
elif exp[pos_search] == ' ':
pos_search += 1
elif state_in_string:

View File

@ -1035,6 +1035,10 @@ union misra_19_2 { }; // 19.2
#define M_20_7_11(A, B, C) (A " " B " " C)
#define M_20_7_12(A, B, C) (A " " B + C) // 20.7
#define M_20_7_13(A, B, C) (A + B " " C) // 20.7
#define M_20_7_14(STRING1, STRING2) (STRING1 " " STRING2)
#define M_20_7_15(STRING1, STRING2, STRING3) (STRING1 " " STRING2 " " STRING3)
#define M_20_7_16(STRING1, STRING2, STRING3) (STRING1 " " STRING2 + STRING3) // 20.7
#define M_20_7_17(STRING1, STRING2, STRING3) (STRING1 + STRING2 " " STRING3) // 20.7
// Compliant: M is a structure member name, not an expression
struct { int a; } struct_20_7_s;