From 055c7007e520c103c41b5b50101357531978d7aa Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sun, 30 Apr 2017 11:06:43 +0200 Subject: [PATCH] refactor cJSONUtils_strdup --- cJSON_Utils.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cJSON_Utils.c b/cJSON_Utils.c index c6308bf..3b7cfbc 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -30,17 +30,18 @@ #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; - len = strlen((const char*)str) + 1; - if (!(copy = (unsigned char*)cJSON_malloc(len))) + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*) cJSON_malloc(length); + if (copy == NULL) { return NULL; } - memcpy(copy, str, len); + memcpy(copy, string, length); return copy; }