Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misra 9.2: do not crash when checking. string literal is allowed to initialize array member. #5232

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions addons/misra_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __repr__(self):

attrs = ["childIndex", "elementType", "valueType"]
return "{}({}, {}, {})".format(
"ED",
"ElementDef",
self.getLongName(),
inits,
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
Expand Down Expand Up @@ -255,6 +255,16 @@ def parseInitializer(self, root, token):
isFirstElement = False
isDesignated = True

elif self.token.isString and self.ed.isArray:
self.ed.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 self.token.str == '{':
nextChild = self.root.getNextChild() if self.root is not None else None

Expand Down Expand Up @@ -316,6 +326,7 @@ def parseInitializer(self, root, token):
else:
self.ed.parent.setInitialized(isDesignated)
self.ed.parent.initializeChildren()

else:
if self.ed.parent != self.root:
# Check if token is correct value type for self.root.children[?]
Expand All @@ -335,7 +346,15 @@ def parseInitializer(self, root, token):
parent = parent.parent
isDesignated = False

self.unwindAndContinue()
if self.token.isString:
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()
else:
self.unwindAndContinue()

def pushToRootStackAndMarkAsDesignated(self):
new = self.ed.parent
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}}
};