From c1d397954fde32f7b309f59f808eb60d99a860d5 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 | 11 ++++++++++- addons/test/misra/misra-test.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index ae3cf59c8bcf..f147c9edfb78 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: @@ -4254,6 +4262,7 @@ def setSuppressionList(self, suppressionlist): self.addSuppressedRule(ruleNum) def report_config_error(self, location, errmsg): + errmsg = 'Because of missing configuration, misra checking is incomplete. There can be false negatives!' + errmsg cppcheck_severity = 'error' error_id = 'config' if self.settings.verify: 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 +}