From 9c5275f514c81cde255102997e357c1a33336cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 11 Jul 2023 17:57:55 +0200 Subject: [PATCH] misra: fix 9.x checking when string literals are used to initialize char arrays (#5234) --- addons/misra_9.py | 12 +++--------- addons/test/misra/crash8.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 addons/test/misra/crash8.c diff --git a/addons/misra_9.py b/addons/misra_9.py index 4ebef9966..02940c440 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -346,15 +346,9 @@ class InitializerParser: parent = parent.parent isDesignated = False - 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() + if self.token.isString and self.ed.parent.isArray: + self.ed = self.ed.parent + self.unwindAndContinue() def pushToRootStackAndMarkAsDesignated(self): new = self.ed.parent diff --git a/addons/test/misra/crash8.c b/addons/test/misra/crash8.c new file mode 100644 index 000000000..970d72540 --- /dev/null +++ b/addons/test/misra/crash8.c @@ -0,0 +1,10 @@ + +struct three_d_filter_t { + char name[16]; + double elem[2]; +}; + +static three_d_filter_t base_filters[] = { + {"Identity", { 1.0, 0.0 } }, + {"Echo", { 0.4, 0.0 } } +};