H
hammer1234
Hello
I would like to create a test case that violates the following MISRA
C:2004 rule .
Misra Rule 18.2. An object shall not be assigned to an overlapping
object.
"The behaviour is undefined when two objects are created which have
some overlap in memory and one is copied to the other"
The sample I have created is
---------------------------------------------------------------
#include <string.h>
typedef char char_t;
char_t main(void)
{
char_t Buffer[]= "is this a violation?";
memcpy(&Buffer[5], &Buffer[10], 10); /*Violation, memory over lapped,
result will equal "is thviolation?tion?"*/
return(Buffer[5]);
}
-------------------------------------------------------------------------------------
However the rule relates to copying one object to another different
object where the two objects have some memory overlapping. It could
possibly be related to using unions.
Can anyone think of a way I can violate this rule??
I would like to create a test case that violates the following MISRA
C:2004 rule .
Misra Rule 18.2. An object shall not be assigned to an overlapping
object.
"The behaviour is undefined when two objects are created which have
some overlap in memory and one is copied to the other"
The sample I have created is
---------------------------------------------------------------
#include <string.h>
typedef char char_t;
char_t main(void)
{
char_t Buffer[]= "is this a violation?";
memcpy(&Buffer[5], &Buffer[10], 10); /*Violation, memory over lapped,
result will equal "is thviolation?tion?"*/
return(Buffer[5]);
}
-------------------------------------------------------------------------------------
However the rule relates to copying one object to another different
object where the two objects have some memory overlapping. It could
possibly be related to using unions.
Can anyone think of a way I can violate this rule??