Rule 11.9: Does array initialization to 0 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 array initialization to 0 violate Rule 11.9?

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

Dear community,

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

uint8 myBuffer[8] = {0u}; // with "typedef unsigned char uint8;"

Unfortunately, neither from the tool documentation nor from the MISRA documentation we can conclude why this "standard" construct 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

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

Re: Rule 11.9: Does array initialization to 0 violate Rule 11.9?

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

There is no null pointer constant in this example and hence no violation of rule 11.9.

However there is a violation of rule 9.3 since the array is only partially initialized.

Valid initializations would be:

Code: Select all

uint8 myBuffer[ 8 ] = { 0u,0u,0u,0u,0u,0u,0u,0u };
uint8 myBuffer[ 8 ] = { 0 };
The use of "0" is a special case which is permitted by exception in rule 9.3 and 10.3.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.11 Pointer type conversions”