Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Jul 10, 2023
1 parent 711e8e6 commit 3607f9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 9 additions & 4 deletions addons/misra_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3607f9a

Please sign in to comment.