### _debug_strncat -- Concatenate Strings

Format

>     #include <string.h>
>     char *_debug_strncat(char *string1, const char *string2, size_t count,
>                         const char *filename, size_t line);

Language Level: Extension
_debug_strncat is the debug version of strncat. Like strncat, it appends the first count characters of string2 to string1 and ends the resulting string with a null character (\0). If count is greater than the length of string2, the length of string2 is used in place of count.

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

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

Example
This example is similar to the strncat example, except that it contains a programming error. The buffer1 object is not large enough to store the result after eight characters from the string " programming" are concatenated.

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

    #define  SIZE          10

    int main(void)
    {
       char *buffer1;
       char *ptr;

       buffer1 = (char*)malloc(SIZE);
       strcpy(buffer1, "computer");

       /* Call strncat with buffer1 and " program"                                */

       ptr = strncat(buffer1, " programming", 8);
       printf("strncat: buffer1 = \"%s\"\n", buffer1);
       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: 636F6D7075746572.
          This memory block was (re)allocated at line number 12 in strncat.c.
          Heap state was valid at line 13 of strncat.c.
          Memory error detected at line 17 of strncat.c.
       ****************************************************************************/
    }

Managing Memory with Multiple Heaps

_debug_strcat -- Concatenate Strings
_heap_check -- Validate Default Memory Heap
strcat -- Concatenate Strings
strncat -- Concatenate Strings
<string.h>
/Tm compiler option