|
|
@@ -96,9 +96,9 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
|
|
|
return (const char*) (global_error.json + global_error.position);
|
|
|
}
|
|
|
|
|
|
-CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
|
|
|
+CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
|
|
|
{
|
|
|
- if (!cJSON_IsString(item))
|
|
|
+ if (!cJSON_IsString(item))
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
@@ -106,9 +106,9 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
|
|
|
return item->valuestring;
|
|
|
}
|
|
|
|
|
|
-CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
|
|
|
+CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
|
|
|
{
|
|
|
- if (!cJSON_IsNumber(item))
|
|
|
+ if (!cJSON_IsNumber(item))
|
|
|
{
|
|
|
return (double) NAN;
|
|
|
}
|
|
|
@@ -117,7 +117,7 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
|
|
|
}
|
|
|
|
|
|
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
|
|
|
-#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15)
|
|
|
+#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 16)
|
|
|
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
|
|
#endif
|
|
|
|
|
|
@@ -184,7 +184,7 @@ typedef struct internal_hooks
|
|
|
/* strlen of character literals resolved at compile time */
|
|
|
#define static_strlen(string_literal) (sizeof(string_literal) - sizeof(""))
|
|
|
|
|
|
-static const internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc };
|
|
|
+static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc };
|
|
|
|
|
|
static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks)
|
|
|
{
|
|
|
@@ -512,7 +512,7 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
memcpy(newbuffer, p->buffer, p->offset + 1);
|
|
|
p->hooks.deallocate(p->buffer);
|
|
|
}
|
|
|
@@ -563,6 +563,10 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
|
|
|
{
|
|
|
length = sprintf((char*)number_buffer, "null");
|
|
|
}
|
|
|
+ else if(d == (double)item->valueint)
|
|
|
+ {
|
|
|
+ length = sprintf((char*)number_buffer, "%d", item->valueint);
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
|
|
|
@@ -1104,7 +1108,7 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer
|
|
|
}
|
|
|
|
|
|
buffer.content = (const unsigned char*)value;
|
|
|
- buffer.length = buffer_length;
|
|
|
+ buffer.length = buffer_length;
|
|
|
buffer.offset = 0;
|
|
|
buffer.hooks = global_hooks;
|
|
|
|
|
|
@@ -2288,7 +2292,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON
|
|
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
|
|
|
{
|
|
|
- if ((parent == NULL) || (replacement == NULL) || (item == NULL))
|
|
|
+ if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
@@ -2358,6 +2362,11 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO
|
|
|
cJSON_free(replacement->string);
|
|
|
}
|
|
|
replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
|
|
|
+ if (replacement->string == NULL)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
replacement->type &= ~cJSON_StringIsConst;
|
|
|
|
|
|
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
|
|
|
@@ -2690,7 +2699,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
|
|
|
if (a && a->child) {
|
|
|
a->child->prev = n;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return a;
|
|
|
}
|
|
|
|