MISRA Discussion Forums
Dir 4.14 - How to check pointer to structure - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 7.4 Code design (https://forum.misra.org.uk/forumdisplay.php?fid=181)
+---- Thread: Dir 4.14 - How to check pointer to structure (/showthread.php?tid=1471)



Dir 4.14 - How to check pointer to structure - apereira - 15-02-2019

For example:
Code:
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 - dg1980 - 15-02-2019

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 - apereira - 15-02-2019

This is in Amendment 1: https://www.misra.org.uk/LinkClick.aspx?fileticket=V2wsZxtVGkE%3D&tabid=57


Re: Dir 4.14 - How to check pointer to structure - dg1980 - 15-02-2019

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 - apereira - 15-02-2019

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 - misra-c - 07-03-2019

The amplification of Directive 4.14 gives a list of the sort of "external sources" that are covered by this directive.