### _debug_strnset -- Set Characters in String

Format

>     #include <string.h>
>     char *_debug_strnset(char *string, int c, size_t n,
>                         const char *filename, size_t line);

Language Level: Extension
_debug_strnset is the debug version of strnset. Like strnset, it sets, at most, the first n characters of string to c (converted to a char), where if n is greater than the length of string, the length of string is used in place of n.

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

Note: _debug_strnset 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_strnset, you must compile with the debug memory (/Tm) compiler option. This option maps all strnset calls to _debug_strnset. 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 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_strnset returns a pointer to the altered string. There is no error return value.

Example
This example is similar to the strnset example, except that it contains two programming errors. The string, str, was created without a null-terminator to mark the end of the string, and without the terminator strnset with a count of 10 stores bytes past the end of the allocated object.

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

    int main(void)
    {
       char *str;

       str = (char*)malloc(10);

       printf("This is the string after strnset: %s\n", str);
       return 0;

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

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

Managing Memory with Multiple Heaps

_debug_memset -- Set Bytes to Value
_debug_strset -- Set Characters in String
_heap_check -- Validate Default Memory Heap
strnset - strset -- Set Characters in String
<string.h>
/Tm compiler option