![]() |
![]() |
2777 | ![]() |
||||
![]() | |||||||
| Pointers | |||||||
An apparent condition has been detected. Examination of the context indicates that an operation is being performed which will sometimes attempt to copy data between two objects which overlap in memory. The behaviour will be undefined. It may be advisable to use the function 'memmove' instead. For example, in the code below, the buffers addressed by pointers 'p1' and 'p2' will overlap if the value of the function parameter 'n' exceeds '3',
/*PRQA S 315,702,1253,2017,2211,3120,3132,3227,3408,3447 ++ */
#include <string.h>
extern int buf1[10];
extern void f2777(int p)
{
int * p1;
int * p2;
unsigned int n = 1;
p1 = buf1;
p2 = &buf1[3];
if (p > 0)
{
n = 5;
}
(void)memcpy (p1, p2, n * sizeof(int)); /* 2777 */
(void)memmove(p1, p2, n * sizeof(int)); /* */
}
MISRA-C:2004 Rules applicable to message 2777:
| Rule 18.2 (Required) | An object shall not be assigned to an overlapping object. |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |