From c972140701262d390fdd8716d4daff6cf1d7cb3e Mon Sep 17 00:00:00 2001 From: swasti16 Date: Sat, 17 Feb 2024 16:10:47 +0530 Subject: [PATCH] Fix 12448: False positive: misra-config about unknown variable after struct keyword --- addons/misra.py | 10 +++++++++- addons/test/misra/misra-test.c | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index ae3cf59c8bcf..e9e384346963 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -3342,7 +3342,15 @@ def misra_config(self, data): continue if tok.astParent.str == "." and tok.astParent.valueType: continue - self.report_config_error(tok, "Variable '%s' is unknown" % tok.str) + tok_pre = tok.previous + name = False + while tok_pre.isName or tok_pre.str == "*": + if tok_pre.str != '*': + name = True + break + tok_pre = tok_pre.previous + if not name: + self.report_config_error(tok, "Variable '%s' is unknown" % tok.str) def misra_17_6(self, rawTokens): for token in rawTokens: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index d1ece87f2b2e..a15201efeb5a 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -2035,3 +2035,13 @@ static void misra_22_10(void) f = strtod(inStr, NULL_PTR); if(errno != 0) {} } + +// #12448 +static void check_misra_config(void) +{ + if (sizeof(struct bar) == 0U) {} //no warning + if (sizeof(int abc) == 0U) {} //no warning + if (sizeof(xyz) == 0U) {} //config + if (sizeof(const pqr) == 0U) {} //no warning + if (sizeof(const int* const pqrs) == 0U) {} //no-warning +}