Rule 11.9: Does this struct initialization violate rule 11.9?

Moderators: misra-c, david ward

Post Reply
fst-mra
Posts: 2
Joined: Fri Sep 22, 2017 9:05 am
Company: IAV

Rule 11.9: Does this struct initialization violate rule 11.9?

Post by fst-mra » Wed Sep 27, 2017 11:09 am

Dear community,

our analysis tool reports the following struct initialization to violate rule 11.9 (macro NULL is the only permitted form of integer null pointer constant):

static const myType myStruct = {
64,
{0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0},
0
};

with:
typedef unsigned short uint16;
typedef unsigned char uint8;
typedef struct {
uint16 myVariable01;
uint8 myArray [16];
uint8 myVariable02;
} myType;

Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this initialization would be non-compliant. Also we cannot see what the risk behind this deviation would be. Is this deviation false-positive? Does it introduce any portability, maintainability etc. risk?

Thanks for your support.
Frank

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 11.9: Does this struct initialization violate rule 11.9?

Post by dg1980 » Thu Sep 28, 2017 10:18 am

Code: Select all

typedef struct {
uint16 myVariable01;
uint8 myArray [16];
uint8 myVariable02;
} myType;
Since myType does not contain a pointer and NULL macro is not even used in initialization, it is a false positive IMHO.
A violation would look like this:

Code: Select all

uint8* ptr = 0;// use NULL for pointer initialization

misra-c
Posts: 571
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 11.9: Does this struct initialization violate rule 11.9?

Post by misra-c » Tue Oct 24, 2017 2:13 pm

There is no null pointer constant in this example and hence no violation of rule 11.9
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.11 Pointer type conversions”