6.20 Standard Libraries
Moderators: misra-c, david ward
- Posts: 1
- Joined: Fri Feb 03, 2017 5:36 am
- Company: Medtronic India
Code: Select all
#define MAX_BUF_LEN 20
#define MAX_ID_LEN 40
uint8_t ID[MAX_ID_LEN ];'
uint8_t ID[MAX_ID_LEN ];
memcpy(pfdata.ID, testdata.ID, MAX_ID_LEN ); // Misra not compliant
I am using parasoft tool for checking misra compliance. for the above memcpy line I am getting the following misra non compliance
Values is "ID" passed to library function "memcpy" without being checked
I am using statically declared array. Why is it throwing this misra compliance? Can any one point how to make thsi line compliant
- Posts: 109
- Joined: Wed Apr 27, 2016 2:33 pm
- Company: Elektrobit Automotive GmbH
Rule 20.3 requires parameter checking for library functions, although memcpy is not explicitly mentioned.
The behaviour of memcpy is undefined, if the memory regions overlap.
However, in your example it is provable by static analysis that this can never be the case.
Excerpt from Rule 20.3:
Demonstrate statically that the input parameters never can take invalid values
So, long story short: false positive, contact tool vendor.
- Posts: 566
- Joined: Thu Jan 05, 2006 1:11 pm
dg1980 has correctly pointed out that there are various ways to satisfy this rule. In MISRA-C:2012 this rule has become a directive (4.11), which highlights that the MISRA-C team is not mandating exactly what a tool should be checking for. Therefore tools will vary in how they perform this check.
In this particular case it CAN BE statically demonstrated that there are no issues of undefined behaviour since the input parameters are valid.
Posted by and on behalf of
the MISRA C Working Group