### _debug_memset -- Set Bytes to Value

Format

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

Language Level: Extension
_debug_memset is the debug version of memset. Like memset, it sets the first count bytes of dest to the value c. The value of c is converted to an unsigned character.

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

Note: _debug_memset 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_memset, you must compile with the debug memory (/Tm) compiler option. This option maps all memset calls to _debug_memset. You do not have to change your source code, in order for _debug_memset 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_memset returns a pointer to dest.

Example
This example is similar to the memset example, except that it contains a programming error. The invocation of memset that puts 'B' in the buffer specifies the wrong count, and stores bytes past the end of the buffer.

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

    #define  BUF_SIZE      20

    int main(void)
    {
       char *buffer, *buffer2;
       char *string;

       buffer = (char*)calloc(1, BUF_SIZE+1);    /* +1 for null-terminator */

       string = (char*)memset(buffer, 'A', 10);
       printf("\nBuffer contents: %s\n", string);
       memset(buffer+10, 'B', 20);

       return 0;

       /****************************************************************************
          The output should be:

          Buffer contents: AAAAAAAAAA
          End of allocated object 0x00073c80 was overwritten at 0x00073c95.
          The first eight bytes of the memory block (in hex) are: 4141414141414141.
          This memory block was (re)allocated at line number 12 in memset.c.
          Heap state was valid at line 14 of memset.c.
          Memory error detected at line 16 of memset.c.
       ****************************************************************************/
    }

Managing Memory with Multiple Heaps

_debug_memcpy -- Copy Bytes
_debug_memmove -- Copy Bytes
_heap_check -- Validate Default Memory Heap
memmove -- Copy Bytes
<string.h>
/Tm compiler option