Page 1 of 1

Dir 4.14 - How to check pointer to structure

Posted: Fri Feb 15, 2019 7:52 am
by apereira
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?

Re: Dir 4.14 - How to check pointer to structure

Posted: Fri Feb 15, 2019 8:47 am
by dg1980
There is no such Directive in MISRA C 2012 (Directive 4.13 is the highest number)?

Re: Dir 4.14 - How to check pointer to structure

Posted: Fri Feb 15, 2019 9:31 am
by apereira

Re: Dir 4.14 - How to check pointer to structure

Posted: Fri Feb 15, 2019 9:57 am
by dg1980
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.

Re: Dir 4.14 - How to check pointer to structure

Posted: Fri Feb 15, 2019 3:44 pm
by apereira
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!

Re: Dir 4.14 - How to check pointer to structure

Posted: Thu Mar 07, 2019 9:25 am
by misra-c
The amplification of Directive 4.14 gives a list of the sort of "external sources" that are covered by this directive.