Format
#include <string.h>
void *_debug_memmove(void *dest, const void *src, size_t count,
const char *filename, size_t line);
Language Level: Extension
_debug_memmove is the debug version of memmove. Like
memmove, it copies count bytes of src to dest,
and allows for copying between objects that may overlap.
_debug_memmove validates the heap after copying the bytes to the target location, and performs this check only when the target is within a heap. _debug_memmove makes an implicit call to _heap_check. If _debug_memmove detects a corrupted heap when it makes a call to _heap_check, _debug_memmove will report the file name file and line number line in a message.
Note: _debug_memmove 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_memmove, you must compile with the debug memory (/Tm) compiler option. This option maps all memcpy calls to _debug_memmove. You do not have to change your source code, in order for _debug_memmove 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_memmove returns a pointer to dest.
Example
This example is similar to the memmove example, except that it
contains a programming error. The count specified on memmove is
15 instead of 5, and the memmove operation copies bytes past the
end of the allocated object.
#include <stdlib.h> #include <string.h> #include <stdio.h>
#define SIZE 21
int main(void)
{
char *target, *p, *source;
target = (char*)malloc(SIZE);
strcpy(target, "a shiny white sphere");
p = target+8; /* p points at the starting character
of the word we want to replace */
source = target+2; /* start of "shiny" */
printf("Before memmove, target is \"%s\"\n", target);
memmove(p, source, 15);
printf("After memmove, target becomes \"%s\"\n", target);
return 0;
/****************************************************************************
The output should be similar to:
Before memmove, target is "a shiny white sphere"
End of allocated object 0x00073c80 was overwritten at 0x00073c95.
The first eight bytes of the memory block (in hex) are: 61207368696E7920.
This memory block was (re)allocated at line number 11 in memmove.c.
Heap state was valid at line 12 of memmove.c.
Memory error detected at line 18 of memcpy.c.
****************************************************************************/
}
![]()
Managing Memory
with Multiple Heaps
![]()
_debug_memcpy -- Copy Bytes
_debug_memset -- Set Bytes to Value
_heap_check -- Validate Default Memory
Heap
memmove -- Copy Bytes
<string.h>
/Tm compiler option