_debug_strcat - Concatenate Strings

Format

#include <string.h>

char *_debug_strcat(char *string1, const char *string2,

                    const char *file, size_t file);

Language Level: Extension

_debug_strcat is the debug version of strcat. Like strcat, it concatenates string2 to string1 and ends the resulting string with the null character.

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

Note: _debug_strcat 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_strcat, you must compile with the debug memory -qheapdebug compiler option. This option maps all strcat calls to _debug_strcat. You do not have to change your source code, in order for _debug_strcat to verify the heap.

Note: The -qheapdebug 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_strcat
returns a pointer to the concatenated string string1.

Example
This example contains a programming error. The buffer1 object is not large enough to store the result after the string " program" is 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");
   ptr = strcat(buffer1, " program");
   printf("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 strcat.c.
      Heap state was valid at line 13 of strcat.c.
      Memory error detected at line 15 of strcat.c.

   ****************************************************************************/
}


Debugging Memory Heaps
Memory Management Functions
Managing Memory with Multiple Memory Heaps


Debugging Problems with Heap Memory


-qheapdebug Compiler Option
_debug_calloc - Allocate and Initialize Memory
_debug_free - Free Allocated Memory
_debug_heapmin - Free Unused Memory in the Default Heap
_debug_malloc - Allocate Memory
_debug_memcpy - Copy Bytes
_debug_memmove - Copy Bytes
_debug_memset - Set Bytes to Value
_debug_realloc - Reallocate Memory Block
_debug_strcpy - Copy Strings
_debug_strncat - Concatenate Strings
_debug_strncpy - Copy Strings
_debug_strnset - Set Characters in String
_debug_strset - Set Characters in String
_debug_ucalloc - Reserve and Initialize Memory from User Heap
_debug_uheapmin - Free Unused Memory in User Heap
_debug_umalloc - Reserve Memory Block from User Heap