### _debug_memcpy -- Copy Bytes

Format

>     #include <string.h>
>     void *_debug_memcpy(void *dest, const void *src, size_t count,
>                         const char *filename, size_t line);

Language Level: Extension
_debug_memcpy is the debug version of memcpy. Like memcpy, it copies count bytes of src to dest, where the behavior is undefined if copying takes place between objects that overlap.

_debug_memcpy validates the heap after copying the bytes to the target location, and performs this check only when the target is within a heap. _debug_memcpy makes an implicit call to _heap_check. If _debug_memcpy detects a corrupted heap when it makes a call to _heap_check, _debug_memcpy will report the file name file and line number line in a message.

Note: _debug_memcpy checks only the current default heap. Therefore, this debug support will not check all heaps within applications that have multiple user heaps.

To use _debug_memcpy, you must compile with the debug memory (/Tm) compiler option. This option maps all memcpy calls to _debug_memcpy. You do not have to change your source code, in order for _debug_memcpy to verify the heap.

Note: The /Tm option maps all calls to other string functions and all calls to memory management functions (including a heap-specific version), to their debug counterparts. To prevent a call from being mapped, parenthesize the function name.

Return Value
_debug_memcpy returns a pointer to dest.

Example
This example is similar to the memcpy example, except that it contains a programming error. On the memcpy used to initialize the target location, the count is more than the size of the target object, and the memcpy operation copies bytes past the end of the allocated object.

    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>

    #define  MAX_LEN       10

    int main(void)
    {
       char *source, *target;

       target = (char*)malloc(MAX_LEN);
       memcpy(target, "This is the target string", 11);

       printf("Target is \"%s\"\n", target);
       return 0;

       /****************************************************************************
          The output should be similar to:

          End of allocated object 0x00073c80 was overwritten at 0x00073c8a.
          The first eight bytes of the memory block (in hex) are: 5468697320697320.
          This memory block was (re)allocated at line number 11 in memcpy.c.
          Heap state was valid at line 11 of memcpy.c.
          Memory error detected at line 12 of memcpy.c.
       ****************************************************************************/
    }

Managing Memory with Multiple Heaps

_debug_memmove -- Copy Bytes
_debug_memset -- Set Bytes to Value
_heap_check -- Validate Default Memory Heap
memcpy -- Copy Bytes
<string.h>
/Tm compiler option