From 390a5af0645ca565d1ddb395fa716b8cde8daee1 Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Sat, 20 Mar 2021 15:59:39 +0300 Subject: [PATCH] misra.py: Fix crashes on obsolete GCC syntax for struct initialization (#3175) * misra.py: Fix crashes on obsolete GCC syntax for struct initialization * Added expected violations --- addons/misra_9.py | 2 ++ addons/test/misra/misra-test.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/addons/misra_9.py b/addons/misra_9.py index 5f0b9d624..653245322 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -98,6 +98,8 @@ class ElementDef: def getNextValueElement(self, root): current = self while current != root: + if not current.parent: + return None # Get next index of parent i = current.parent.children.index(current) + 1 # Next index of parent exists diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index d0c763af2..32ad998c6 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -442,6 +442,9 @@ void misra_9_struct_initializers() { dummy_struct dsd[2][2] = { 1, 2, 3, 4 }; // 9.2 dummy_struct dse[3] = { {1,2}, {3,4}, [1] = {5,6} }; // 9.3 9.4 dummy_struct dsd[] = { [0] = 1 }; // 9.5 + + // Obsolete initialization syntax for GCC + struct1 os1 = { i1: 1, i2: 2 }; // 10.4 13.4 } void misra_9_broken_initializers() {