>>The issue is that I cannot be certain that the length of str1 is enough to hold both str1 and str2.
And there is no way to do that in C language. C language lets the programmer do a lot of things that are potentially harmful to the program, and buffer overruns are just one of them. There is no way to determine how much memory was allocated to a pointer, or if any memory was allocated at all. There are several ways to crash strcat(), insufficient memory for destination string is just one of them. Another way is pass a string literal as the destination string, such as strcat("Hello","World");
is a guaranteed way to trash memory. And a couple little more subtle ways to trash memory
char* destination = "Hello";
strcat(destination,"World");
void foo(char* dest, char*source)
{
strcat(dest,source);
}
int main()
{
foo("Hello","World");
}