Skip to content

Commit 8050448

Browse files
authored
Fix 12448: False positive: misra-config about unknown variable after struct keyword (#5991)
1 parent f06b989 commit 8050448

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

addons/misra.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,6 +3327,9 @@ def misra_config(self, data):
33273327
end_token = tok.link
33283328
while tok != end_token:
33293329
tok = tok.next
3330+
if tok.str == 'sizeof' and tok.next.str == '(':
3331+
tok = tok.next.link
3332+
continue
33303333
if tok.str == "(" and tok.isCast:
33313334
tok = tok.link
33323335
continue
@@ -4254,6 +4257,7 @@ def setSuppressionList(self, suppressionlist):
42544257
self.addSuppressedRule(ruleNum)
42554258

42564259
def report_config_error(self, location, errmsg):
4260+
errmsg = 'Because of missing configuration, misra checking is incomplete. There can be false negatives! ' + errmsg
42574261
cppcheck_severity = 'error'
42584262
error_id = 'config'
42594263
if self.settings.verify:

addons/test/misra/misra-test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,3 +2035,13 @@ static void misra_22_10(void)
20352035
f = strtod(inStr, NULL_PTR);
20362036
if(errno != 0) {}
20372037
}
2038+
2039+
// #12448
2040+
static void check_misra_config(void)
2041+
{
2042+
if (sizeof(struct bar) == 0U) {} //no warning
2043+
if (sizeof(int abc) == 0U) {} //no warning
2044+
if (sizeof(xyz) == 0U) {} //no warning
2045+
if (sizeof(const pqr) == 0U) {} //no warning
2046+
if (sizeof(const int* const pqrs) == 0U) {} //no-warning
2047+
}

0 commit comments

Comments
 (0)