Skip to content

Commit

Permalink
misra 9.2: do not crash when checking. string literal is allowed to i…
Browse files Browse the repository at this point in the history
…nitialize array member.
  • Loading branch information
danmar committed Jul 10, 2023
1 parent 2cd1f0f commit 652648b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
14 changes: 12 additions & 2 deletions addons/misra_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,21 @@ def parseInitializer(self, root, token):
isFirstElement = False
isDesignated = True

elif self.token.str == '{':
elif self.token.str == '{' or self.token.isString:
nextChild = self.root.getNextChild() if self.root is not None else None

if nextChild:
if nextChild.isArray or nextChild.isRecord:
if nextChild.isArray and self.token.isString:
# Zero initializer causes recursive initialization
nextChild.setInitialized(isDesignated)
if self.token == self.token.astParent.astOperand1 and self.token.astParent.astOperand2:
self.token = self.token.astParent.astOperand2
self.ed.markAsCurrent()
self.ed = self.root.getNextChild()
else:
self.unwindAndContinue()
continue
elif nextChild.isArray or nextChild.isRecord:
nextChild.unset()
nextChild.setInitialized(isDesignated)
self.ed = nextChild.getFirstValueElement()
Expand Down
17 changes: 17 additions & 0 deletions addons/test/misra/crash6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


typedef struct _tGames
{
char magicdirname[10];
unsigned int expectedmask;
unsigned char pictureorder[3];
} tGames;

static const tGames games[1]={
{"Pawn", 1, {0,1,2}}
};





0 comments on commit 652648b

Please sign in to comment.