mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
cJSON_strdup: improve readability
This commit is contained in:
parent
655c26ada1
commit
eb5000ba61
12
cJSON.c
12
cJSON.c
@ -103,22 +103,22 @@ typedef struct internal_hooks
|
|||||||
|
|
||||||
static internal_hooks global_hooks = { malloc, free, realloc };
|
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;
|
unsigned char *copy = NULL;
|
||||||
|
|
||||||
if (str == NULL)
|
if (string == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen((const char*)str) + sizeof("");
|
length = strlen((const char*)string) + sizeof("");
|
||||||
if (!(copy = (unsigned char*)hooks->allocate(len)))
|
if (!(copy = (unsigned char*)hooks->allocate(length)))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(copy, str, len);
|
memcpy(copy, string, length);
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user