From a6c98e9e60eb4fe663fe0b9b877d37b4602449df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 17 Sep 2021 14:21:25 +0200 Subject: [PATCH] Fixed #10482 (FP: misra-c2012-12.2) --- .github/workflows/CI-unixish.yml | 1 + addons/misra.py | 16 ++++++++-------- addons/test/misra/misra-test-avr8.c | 7 +++++++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 addons/test/misra/misra-test-avr8.c diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index b71ab1759..ed3317929 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -146,6 +146,7 @@ jobs: ./cppcheck --addon=misra --inline-suppr --enable=information --error-exitcode=1 addons/test/misra/misra-ctu-*-test.c cd addons/test ../../cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64 && python3 ../misra.py -verify misra/misra-test.c.dump + ../../cppcheck --addon=misra --platform=avr8 --error-exitcode=1 misra/misra-test-avr8.c - name: Build GUI on ubuntu if: contains(matrix.os, 'ubuntu') diff --git a/addons/misra.py b/addons/misra.py index 391958ce1..f17a6e668 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -568,19 +568,19 @@ def getEssentialType(expr): def bitsOfEssentialType(ty): if ty is None: return 0 - ty = ty.split(' ')[-1] - if ty == 'Boolean': + last_type = ty.split(' ')[-1] + if last_type == 'Boolean': return 1 - if ty == 'char': + if last_type == 'char': return typeBits['CHAR'] - if ty == 'short': + if last_type == 'short': return typeBits['SHORT'] - if ty == 'int': + if last_type == 'int': return typeBits['INT'] - if ty == 'long': - return typeBits['LONG'] - if ty == 'long long': + if ty.endswith('long long'): return typeBits['LONG_LONG'] + if last_type == 'long': + return typeBits['LONG'] for sty in STDINT_TYPES: if ty == sty: return int(''.join(filter(str.isdigit, sty))) diff --git a/addons/test/misra/misra-test-avr8.c b/addons/test/misra/misra-test-avr8.c new file mode 100644 index 000000000..33d8fad16 --- /dev/null +++ b/addons/test/misra/misra-test-avr8.c @@ -0,0 +1,7 @@ +// To test: +// ~/cppcheck/cppcheck --addon=misra --platform=avr8 misra-test-avr8.c + +static void misra_12_2(void) { + a = (((uint64_t)0xFF) << 32); +} +