diff --git a/addons/misra_9.py b/addons/misra_9.py index 127b1cf0d6f..d047f09a2c1 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -393,20 +393,25 @@ def misra_9_x(self, data, rule, rawTokens = None): while tok.str == '[': sz = tok.astOperand2 if sz and sz.getKnownIntValue() is None: - has_config_errors = True - err = False + has_var = False + unknown_constant = False tokens = [sz] while len(tokens) > 0: t = tokens[-1] tokens = tokens[:-1] if t: if t.isName and t.getKnownIntValue() is None: - err = True + if t.varId or t.variable: + has_var = True + continue + unknown_constant = True cppcheckdata.reportError(sz, 'error', f'Unknown constant {t.str}, please review configuration', 'misra', 'config') + has_config_errors = True if t.isArithmeticalOp: tokens += [t.astOperand1, t.astOperand2] - if not err: + if not unknown_constant and not has_var: cppcheckdata.reportError(sz, 'error', 'Unknown array size, please review configuration', 'misra', 'config') + has_config_errors = True tok = tok.link.next if has_config_errors: return diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 8467433926c..2fd30c7e707 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -586,10 +586,6 @@ static void misra_9_struct_initializers(void) { struct1 os1 = { i1: 1, i2: 2 }; // 10.4 13.4 } -static void misra_9_broken_initializers(void) { - char a[UNKNOWN_MACRO] = { 19, 23, 0 }; // 18.8 -} - static void misra_9_2(void) { union misra_9_2_union { // 19.2 char c;