in src/umocktypes_charptr.c [228:270]
int umocktypes_copy_const_charptr(const char** destination, const char** source)
{
int result;
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_033: [ If source or destination are NULL, umocktypes_copy_const_charptr shall return a non-zero value. ]*/
if ((destination == NULL) || (source == NULL))
{
UMOCK_LOG("umocktypes_copy_const_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_029: [ The number of bytes allocated shall accomodate the string pointed to by source. ]*/
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_028: [ umocktypes_copy_const_charptr shall allocate a new sequence of chars by using umockalloc_malloc. ]*/
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_031: [ 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_037: [ If allocating the memory for the new string fails, umocktypes_copy_const_charptr shall fail and return a non-zero value. ]*/
UMOCK_LOG("umocktypes_copy_const_charptr: Cannot allocate memory for destination string.");
result = __LINE__;
}
else
{
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_030: [ umocktypes_copy_const_charptr shall copy the string pointed to by source to the newly allocated memory. ]*/
(void)memcpy((void*)*destination, *source, source_length + 1);
/* Codes_SRS_UMOCKTYPES_CHARPTR_01_032: [ On success umocktypes_copy_const_charptr shall return 0. ]*/
result = 0;
}
}
}
return result;
}