[previous] MISRA-C:2004  Rule  18.2:  (Required) [next] 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.

Example Code:


#include "misra.h"
#include "m2cmex.h"
#include "string.h"

extern S16 test_1802( void )
{
   PC buf[100] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

   (void)memcpy( &buf[ 10 ], &buf[ 20 ], 20U );                 /* MISRA Violation */

   u16a = 5U;
   (void)memcpy( &buf[ 10 ], &buf[ 20 ], u16a );                /* OK              */

   if (s16a > 0)
   {
       u16a = 30U;
   }

   (void)memcpy( &buf[ 10 ], &buf[ 20 ], u16a );                /* MISRA Violation */

   return 1;
}


QAC messages that encompass this guideline:

2776 Definite: Copy between overlapping objects.
2777 Apparent: Copy between overlapping objects.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents