I'm having trouble with what looks like a false positive when initialising an array of pointers to structs.
In the example below I have two structures being initialised, one with a single pointer to a struct (which passes the checks OK) and one with an array of two pointers to structs (which fails the checks):
Source\test.c:7:9: unusedStructMember : struct member 'statusStruct::One' is never used.
Source\test.c:8:9: unusedStructMember : struct member 'statusStruct::Two' is never used.
Source\test.c:16:19: unusedStructMember : struct member 'testDataStruct1::TestStatusElement' is never used.
Source\test.c:27:19: unusedStructMember : struct member 'testDataStruct2::TestStatusTable' is never used.
Source\test.c:30:24: misra-c2012-9.2 : The initializer for an aggregate or union shall be enclosed in braces
Source\test.c:30:24: misra-c2012-9.3 : Arrays shall not be partially initialized
[The 'is never used' warnings are side effects of extracting this code into a small example!]
test.c:
#defineTOTAL_STATUS_TABLE10typedefstruct{intOne;intTwo;}statusStruct;staticstatusStructStatusArray[TOTAL_STATUS_TABLE];/* This example works OK */typedefstruct{statusStruct*TestStatusElement;}testDataStruct1;statictestDataStruct1testDataTable1={&StatusArray[0];};/* This examples warns that the initializer should be enclosed in braces, and that the array is partially initialized */typedefstruct{statusStruct*TestStatusTable[2];}testDataStruct2;statictestDataStruct2testDataTable2={{&StatusArray[0],/* First element in table */0/* Second element in table */}};
Cppcheck version 2.9
Hi all.
I'm having trouble with what looks like a false positive when initialising an array of pointers to structs.
In the example below I have two structures being initialised, one with a single pointer to a struct (which passes the checks OK) and one with an array of two pointers to structs (which fails the checks):
Source\test.c:7:9: unusedStructMember : struct member 'statusStruct::One' is never used.
Source\test.c:8:9: unusedStructMember : struct member 'statusStruct::Two' is never used.
Source\test.c:16:19: unusedStructMember : struct member 'testDataStruct1::TestStatusElement' is never used.
Source\test.c:27:19: unusedStructMember : struct member 'testDataStruct2::TestStatusTable' is never used.
Source\test.c:30:24: misra-c2012-9.2 : The initializer for an aggregate or union shall be enclosed in braces
Source\test.c:30:24: misra-c2012-9.3 : Arrays shall not be partially initialized
[The 'is never used' warnings are side effects of extracting this code into a small example!]
test.c:
Last edit: srl100 2022-10-28