diff --git a/libs/esl/src/cJSON.c b/libs/esl/src/cJSON.c index 7f9ecb3b4c..c804b8a476 100644 --- a/libs/esl/src/cJSON.c +++ b/libs/esl/src/cJSON.c @@ -92,18 +92,14 @@ static unsigned char* cJSON_strdup(const unsigned char* str, const internal_hook { size_t len = 0; unsigned char *copy = NULL; + const unsigned char *s = str ? str : (unsigned char *)""; - if (str == NULL) - { - return NULL; - } - - len = strlen((const char*)str) + 1; + len = strlen((const char*)s) + 1; if (!(copy = (unsigned char*)hooks->allocate(len))) { return NULL; } - memcpy(copy, str, len); + memcpy(copy, s, len); return copy; } diff --git a/libs/libks/src/cJSON.c b/libs/libks/src/cJSON.c index b5c2ef0100..2c95812104 100644 --- a/libs/libks/src/cJSON.c +++ b/libs/libks/src/cJSON.c @@ -92,18 +92,14 @@ static unsigned char* cJSON_strdup(const unsigned char* str, const internal_hook { size_t len = 0; unsigned char *copy = NULL; + const unsigned char *s = str ? str : (unsigned char *)""; - if (str == NULL) - { - return NULL; - } - - len = strlen((const char*)str) + 1; + len = strlen((const char*)s) + 1; if (!(copy = (unsigned char*)hooks->allocate(len))) { return NULL; } - memcpy(copy, str, len); + memcpy(copy, s, len); return copy; } diff --git a/src/cJSON.c b/src/cJSON.c index cb1f9971a2..85709f1e3b 100644 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -92,18 +92,14 @@ static unsigned char* cJSON_strdup(const unsigned char* str, const internal_hook { size_t len = 0; unsigned char *copy = NULL; + const unsigned char *s = str ? str : (unsigned char *)""; - if (str == NULL) - { - return NULL; - } - - len = strlen((const char*)str) + 1; + len = strlen((const char*)s) + 1; if (!(copy = (unsigned char*)hooks->allocate(len))) { return NULL; } - memcpy(copy, str, len); + memcpy(copy, s, len); return copy; }