in src/strings.c [489:526]
int STRING_copy(STRING_HANDLE handle, const char* s2)
{
int result;
if ((handle == NULL) || (s2 == NULL))
{
/* Codes_SRS_STRING_07_017: [STRING_copy shall return a nonzero value if any of the supplied parameters are NULL.] */
result = MU_FAILURE;
}
else
{
STRING* s1 = handle;
/* Codes_SRS_STRING_07_026: [If the underlying char* refered to by s1 handle is equal to char* s2 than STRING_copy shall be a noop and return 0.] */
if (s1->s != s2)
{
size_t s2Length = strlen(s2);
char* temp = realloc_flex(s1->s, 1, s2Length, 1);
if (temp == NULL)
{
LogError("Failure in realloc_flex(s1->s=%s, 1, s2Length=%zu, 1);",
s1->s, s2Length);
/* Codes_SRS_STRING_07_027: [STRING_copy shall return a nonzero value if any error is encountered.] */
result = MU_FAILURE;
}
else
{
s1->s = temp;
memmove(s1->s, s2, s2Length + 1);
result = 0;
}
}
else
{
/* Codes_SRS_STRING_07_033: [If overlapping pointer address is given to STRING_copy the behavior is undefined.] */
result = 0;
}
}
return result;
}