Dir 4.14 - How to check pointer to structure

Moderators: misra-c, david ward

apereira
Posts: 3
Joined: Fri Feb 08, 2019 12:57 pm
Company: Infineon Technologies

Dir 4.14 - How to check pointer to structure

Postby apereira » Fri Feb 15, 2019 7:52 am

For example:

Code: Select all

typedef struct myStruct{
   int myParam;
} myStruct;

void fcn(myStruct *const ptr)
{
   ptr->myParam = 1;
}


What is the recommended way to check the struct pointer in this function?

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

Re: Dir 4.14 - How to check pointer to structure

Postby dg1980 » Fri Feb 15, 2019 8:47 am

There is no such Directive in MISRA C 2012 (Directive 4.13 is the highest number)?

apereira
Posts: 3
Joined: Fri Feb 08, 2019 12:57 pm
Company: Infineon Technologies

Re: Dir 4.14 - How to check pointer to structure

Postby apereira » Fri Feb 15, 2019 9:31 am


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

Re: Dir 4.14 - How to check pointer to structure

Postby dg1980 » Fri Feb 15, 2019 9:57 am

Oh, I see.
But i don't think a local pointer classifies as external resource like specified in this particular directive.
If data of type myStruct is received over a communication channel you obviously need some sort of checksum.

apereira
Posts: 3
Joined: Fri Feb 08, 2019 12:57 pm
Company: Infineon Technologies

Re: Dir 4.14 - How to check pointer to structure

Postby apereira » Fri Feb 15, 2019 3:44 pm

Right.
I think that the problem was that these functions were not being used in the application, so the MISRA check was triggering this.
Now that I really use them in the application, I have no more errors.

Thanks for the feedback!

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

Re: Dir 4.14 - How to check pointer to structure

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

The amplification of Directive 4.14 gives a list of the sort of "external sources" that are covered by this directive.
---
Posted by and on behalf of
the MISRA C Working Group


Return to “7.4 Code design”

Who is online

Users browsing this forum: No registered users and 1 guest