From 6f389014f18142bee415ddf3318f0320a20973e1 Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Tue, 6 Jul 2021 18:01:58 +0300 Subject: [PATCH] cppcheckdata: Fix crash on an empty union (#3326) --- addons/cppcheckdata.py | 4 +++- addons/test/misra/misra-test.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 86a35b2b1..43cb78e72 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -404,7 +404,9 @@ class Scope: self.nestedIn = IdMap[self.nestedInId] self.function = IdMap[self.functionId] for v in self.varlistId: - self.varlist.append(IdMap[v]) + value = IdMap.get(v) + if value: + self.varlist.append(value) class Function: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index c6306db29..23ab33415 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -41,6 +41,16 @@ #include // 21.11 #include +// Check that the addon doesn't crash +typedef struct { + union { // 19.2 + struct { + unsigned a : 2; + unsigned : 14; + }; + uint16_t value; + }; +} STRUCT_BITS; typedef unsigned char u8; typedef unsigned short u16;