mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
refactor cJSONUtils_strdup
This commit is contained in:
parent
a1a860cd31
commit
055c7007e5
@ -30,17 +30,18 @@
|
|||||||
|
|
||||||
#include "cJSON_Utils.h"
|
#include "cJSON_Utils.h"
|
||||||
|
|
||||||
static unsigned char* cJSONUtils_strdup(const unsigned char* str)
|
static unsigned char* cJSONUtils_strdup(const unsigned char* const string)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t length = 0;
|
||||||
unsigned char *copy = NULL;
|
unsigned char *copy = NULL;
|
||||||
|
|
||||||
len = strlen((const char*)str) + 1;
|
length = strlen((const char*)string) + sizeof("");
|
||||||
if (!(copy = (unsigned char*)cJSON_malloc(len)))
|
copy = (unsigned char*) cJSON_malloc(length);
|
||||||
|
if (copy == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(copy, str, len);
|
memcpy(copy, string, length);
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user