Someone wrote a function in our C ++ application and is already in production, and I do not know why this is not an application failure. Below is the code.
char *str_Modify()
{
char buffer[70000] = { 0 };
char targetString[70000] = { 0 };
memset(targetString, '\0', sizeof(targetString));
...
...
...
return targetString;
}
As you can see, the function returns the address of the local variable, and the allocated memory will be freed after the function returns. My question
- I wanted to know what is the limit of static data memory?
- What could be a quick fix for this code? Is it good practice to make a
targetString
static variable ?
source
share