From 22613dc7fb385eedeebe5b83781b9926ae80046e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 15 Dec 2023 22:53:19 +0100 Subject: [PATCH] Fixed #12267 (Misra.py: crashes in 17.7 checker when there is macro in variable declaration) (#5768) --- addons/misra.py | 4 ++-- addons/test/misra/crash10.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 addons/test/misra/crash10.c diff --git a/addons/misra.py b/addons/misra.py index a93b9b518..680c8c199 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -3358,9 +3358,9 @@ class MisraChecker: continue if token.str != '(' or token.astParent: continue - if not token.astOperand1 or not token.astOperand1.isName: + if token.astOperand1 is None or not token.astOperand1.isName: continue - if token.astOperand1.varId and get_function_pointer_type(token.astOperand1.variable.typeStartToken) is None: + if token.astOperand1.varId and (token.astOperand1.variable is None or get_function_pointer_type(token.astOperand1.variable.typeStartToken) is None): continue if token.valueType is None: continue diff --git a/addons/test/misra/crash10.c b/addons/test/misra/crash10.c new file mode 100644 index 000000000..455d86e57 --- /dev/null +++ b/addons/test/misra/crash10.c @@ -0,0 +1,12 @@ +//#12267 + +extern uint32_t end; + +//#define KEEP // if uncomment this then wont crash + +KEEP static const int32_t ptr_to_end = &end; + +void foo(void) +{ + (void)ptr_to_end; +}