Skip to content

Commit 91dedf0

Browse files
authored
Fix #11793 (False positive: Misra addon crash for struct initialization when struct has a function pointer array) (cppcheck-opensource#5190)
1 parent 87c2b8d commit 91dedf0

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

.github/workflows/CI-unixish.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ jobs:
380380
run: |
381381
./cppcheck --error-exitcode=1 --inline-suppr --addon=threadsafety addons/test/threadsafety
382382
./cppcheck --error-exitcode=1 --inline-suppr --addon=threadsafety --std=c++03 addons/test/threadsafety
383+
./cppcheck --error-exitcode=1 --addon=misra addons/test/misra/crash*.c
383384
./cppcheck --addon=misra --enable=style --inline-suppr --enable=information --error-exitcode=1 addons/test/misra/misra-ctu-*-test.c
384385
pushd addons/test
385386
# We'll force C89 standard to enable an additional verification for
@@ -403,11 +404,6 @@ jobs:
403404
../../cppcheck --dump namingng_test.c
404405
python3 ../namingng.py --configfile ../naming.json --verify namingng_test.c.dump
405406
406-
- name: Ensure misra addon does not crash
407-
if: contains(matrix.os, 'ubuntu')
408-
run: |
409-
./cppcheck --addon=misra addons/test/misra/crash1.c | ( ! grep 'Bailing out from checking' )
410-
411407
- name: Build democlient
412408
if: matrix.os == 'ubuntu-22.04'
413409
run: |

addons/misra_9.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def getElementDef(nameToken, rawTokens = None):
441441
return ed
442442

443443
def createArrayChildrenDefs(ed, token, var, rawTokens = None):
444-
if token.str == '[':
444+
if token and token.str == '[':
445445
if rawTokens is not None:
446446
foundToken = next((rawToken for rawToken in rawTokens
447447
if rawToken.file == token.file

addons/test/misra/crash2.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
// #11793
3+
4+
typedef struct pfmlib_pmu {
5+
int flags ;
6+
int (*get_event_encoding[10])(void* this, pfmlib_event_desc_t* e);
7+
} pfmlib_pmu_t ;
8+
9+
pfmlib_pmu_t sparc_ultra3_support = { .flags = 0 };

0 commit comments

Comments
 (0)