From 48694e21d68ee10e71c6192b70c118019bad2a0b 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 | 4 ++++ addons/test/misra/misra-test.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/addons/misra.py b/addons/misra.py index ae3cf59c8bc..62a87666490 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -3327,6 +3327,9 @@ def misra_config(self, data): end_token = tok.link while tok != end_token: tok = tok.next + if tok.str == 'sizeof' and tok.next.str == '(': + tok = tok.next.link + continue if tok.str == "(" and tok.isCast: tok = tok.link continue @@ -4254,6 +4257,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 d1ece87f2b2..fc0abdab7ca 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) {} //no warning + if (sizeof(const pqr) == 0U) {} //no warning + if (sizeof(const int* const pqrs) == 0U) {} //no-warning +}