Home > Back-end >  Excuse me, what's the problem with the following code?
Excuse me, what's the problem with the following code?

Time:11-20

Excuse me, what's the problem with the following code?

CodePudding user response:

STR is only a memory, multiple calls will be chaos

CodePudding user response:

Is it possible is the length of strSource may outweigh the MAX_STR_LEN, leading to an array

CodePudding user response:

Possible, so you have a code problem
 
Char * _strdup (const char * strSource)
{
If (strSource==NULL)
return NULL;
Int len=strlen (strSource);
Char * result=(char *) malloc (sizeof (char) * (len + 1));
Strcpy (result, strSource);
Result [len]='\ 0';
return result;
}

CodePudding user response:

1) suspected of crossing the line, this can't avoid an array,
2) multithreaded operations, this function is not atomic operations, multi-threaded operation data content may be chaotic;
  • Related