提交 eb5000ba 编写于 作者: M Max Bruckner

cJSON_strdup: improve readability

上级 655c26ad
......@@ -103,22 +103,22 @@ typedef struct internal_hooks
static internal_hooks global_hooks = { malloc, free, realloc };
static unsigned char* cJSON_strdup(const unsigned char* str, const internal_hooks * const hooks)
static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks)
{
size_t len = 0;
size_t length = 0;
unsigned char *copy = NULL;
if (str == NULL)
if (string == NULL)
{
return NULL;
}
len = strlen((const char*)str) + sizeof("");
if (!(copy = (unsigned char*)hooks->allocate(len)))
length = strlen((const char*)string) + sizeof("");
if (!(copy = (unsigned char*)hooks->allocate(length)))
{
return NULL;
}
memcpy(copy, str, len);
memcpy(copy, string, length);
return copy;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册