diff --git a/Makefile b/Makefile index 7ce253e..b858861 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH) INSTALL ?= cp -a -CC = gcc -std=c89 +CC = gcc -std=c11 # validate gcc version for use fstack-protector-strong MIN_GCC_VERSION = "4.9" diff --git a/cJSON.c b/cJSON.c index a5c230f..39ceaab 100644 --- a/cJSON.c +++ b/cJSON.c @@ -44,7 +44,7 @@ #include #include #include - +#include #ifdef ENABLE_LOCALES #include #endif @@ -312,6 +312,7 @@ typedef struct static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) { double number = 0; + uint64_t number64; unsigned char *after_end = NULL; unsigned char number_c_string[64]; unsigned char decimal_point = get_decimal_point(); @@ -378,7 +379,12 @@ loop_end: { item->valueint = (int)number; } - + number64 = strtoull((const char*)number_c_string, (char**)&after_end, 10); + if(number_c_string == after_end) + { + return false; + } + item->valueint64 = number64; item->type = cJSON_Number; input_buffer->offset += (size_t)(after_end - number_c_string); diff --git a/cJSON.h b/cJSON.h index e482d34..b2dec41 100644 --- a/cJSON.h +++ b/cJSON.h @@ -84,7 +84,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ #define CJSON_VERSION_PATCH 13 #include - +#include /* cJSON Types: */ #define cJSON_Invalid (0) #define cJSON_False (1 << 0) @@ -117,7 +117,7 @@ typedef struct cJSON int valueint; /* The item's number, if type==cJSON_Number */ double valuedouble; - + uint64_t valueint64; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ char *string; size_t valuestring_len; @@ -180,6 +180,7 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); CJSON_PUBLIC(size_t) cJSON_GetStringValueLength(cJSON *item); CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item); +CJSON_PUBLIC(long int) cJSON_Get64NumberValue(cJSON *item); /* These functions check the type of an item */ CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); diff --git a/cJSON_Utils.c b/cJSON_Utils.c index c750f7f..ecc6b86 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -836,7 +836,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_ { if (opcode == REMOVE) { - static const cJSON invalid = { NULL, NULL, NULL, cJSON_Invalid, NULL, 0, 0, NULL}; + static const cJSON invalid = { NULL, NULL, NULL, cJSON_Invalid, NULL, 0, 0, 0, NULL, 0}; overwrite_item(object, invalid); diff --git a/mytest.c b/mytest.c index ecfd3d3..34ebcfa 100644 --- a/mytest.c +++ b/mytest.c @@ -2,7 +2,7 @@ #include #include -char JSON_STR[] = "{ \"val\": \"\\u0000\\u0001\", \"vval\":true, \"test_plain\":\"\\r\\n\", \"plain_text\": \"i'm a text\"}"; +char JSON_STR[] = "{ \"val\": \"\\u0000\\u0001\", \"vval\":true, \"test_plain\":\"\\r\\n\", \"plain_text\": \"i'm a text\", \"test_int64\": 18446744073709551610}"; int main(void) { printf("%s\n", JSON_STR); cJSON *json = cJSON_Parse(JSON_STR); @@ -24,6 +24,11 @@ int main(void) { if(json3 == NULL) { printf("could not get val\n"); } + cJSON *json4 = cJSON_GetObjectItem(json, "test_int64"); + printf("got int 64 val: %016lx\n", json4->valueint64); + double asDouble = cJSON_GetNumberValue(json4); + int asInt = json4->valueint; + printf("got val: %e %lx %u\n",asDouble, *((uint64_t*)&asDouble), asInt); printf("val is : *%s*\nlen is : %lu as opposed to: %lu\n", cJSON_GetStringValue(json3), json3->valuestring_len, strlen(json3->valuestring)); cJSON_Delete(json); return 0;