in src/umocktypes_charptr.c [91:133]
int umocktypes_copy_charptr(char** destination, const char** source)
{
int result;
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_013: [ If source or destination are NULL, umocktypes_copy_charptr shall return a non-zero value. ]*/
if ((destination == NULL) || (source == NULL))
{
UMOCK_LOG("umocktypes_copy_charptr: Bad arguments: destination = %p, source = %p.",
destination, source);
result = __LINE__;
}
else
{
if (*source == NULL)
{
*destination = NULL;
result = 0;
}
else
{
size_t source_length = strlen(*source);
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_012: [ The number of bytes allocated shall accomodate the string pointed to by source. ]*/
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_011: [ umocktypes_copy_charptr shall allocate a new sequence of chars by using umockalloc_malloc. ]*/
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_015: [ The newly allocated string shall be returned in the destination argument. ]*/
*destination = (char*)umockalloc_malloc(source_length + 1);
if (*destination == NULL)
{
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_036: [ If allocating the memory for the new string fails, umocktypes_copy_charptr shall fail and return a non-zero value. ]*/
UMOCK_LOG("umocktypes_copy_charptr: Failed allocating memory for the destination string.");
result = __LINE__;
}
else
{
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_014: [ umocktypes_copy_charptr shall copy the string pointed to by source to the newly allocated memory. ]*/
(void)memcpy(*destination, *source, source_length + 1);
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_016: [ On success umocktypes_copy_charptr shall return 0. ]*/
result = 0;
}
}
}
return result;
}