[previous] MISRA C:2012  Rule-19.1:  (Mandatory) [next] An object shall not be assigned or copied to an overlapping object

Exception:

The following are permitted because the behaviour is well-defined:

  1. Assignment between two objects that overlap exactly and have compatible types (ignoring their type qualifiers)
  2. Copying between objects that overlap partially or completely using The Standard Library function memmove

Example Code:


#include "string.h"
#include "misra.h"
#include "m3cmex.h"

extern int16_t rule_1901( void )
{
   PC buf[100] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

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

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

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

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

   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, 2012
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents