MISRA2004 Rule 17.4 How to solve the Rule violation

6.17 Pointers and Arrays

Moderators: misra-c, david ward

Tejas Kore
Posts: 1
Joined: Sat Feb 16, 2019 4:03 am
Company: Data Patterns India Pvt. Ltd.

MISRA2004 Rule 17.4 How to solve the Rule violation

Postby Tejas Kore » Tue Feb 19, 2019 4:17 am

I have an issue regarding the rule violation in which I'm using a 2D array inside a structure and apparently The Rule 17.4 says it isn't compliant. Is Declaring arryas inside a structure/union not compliant and why is it so? What exactly is the alternative for it?
Help would be appreciated ASAP. Following is the example code. Thanks in advance.

Code: Select all

#include <stdio.h>
void func1(unsigned char abc);

typedef struct teststructure
{
   float buf[5][3];
}teststruct;

int main()
{
   unsigned char abc;

   func1(abc);

}

void func1(unsigned char abc)
{
   teststruct TEST;

   float fData = 54.0;
   TEST.buf[2][1] = fData;
}

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

Re: MISRA2004 Rule 17.4 How to solve the Rule violation

Postby dg1980 » Wed Feb 20, 2019 7:25 am

This is most likely a false positive from the static analysis tool you are using.
Rule 17.4 bans pointer arithmetic but in your sample you use array indexing only, so it is compliant.
I suggest contacting your tool vendors support.

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

Re: MISRA2004 Rule 17.4 How to solve the Rule violation

Postby misra-c » Thu Mar 07, 2019 9:36 am

There is no violation of rule 17.4.
---
Posted by and on behalf of
the MISRA C Working Group

david ward
Moderator
Moderator
Posts: 477
Joined: Wed May 05, 2004 9:05 am
Location: MIRA

Re: MISRA2004 Rule 17.4 How to solve the Rule violation

Postby david ward » Tue Apr 30, 2019 3:56 pm

Question moved here to the correct location
Dr David Ward
MISRA Project Manager


Return to “6.17 Pointers and Arrays”

Who is online

Users browsing this forum: Bing [Bot] and 0 guests