diff --git a/cJSON.c b/cJSON.c index ca824f0e..c3631b43 100644 --- a/cJSON.c +++ b/cJSON.c @@ -142,7 +142,7 @@ static int case_insensitive_strcmp(const unsigned char *string1, const unsigned return 0; } - for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { if (*string1 == '\0') { @@ -608,7 +608,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out { length = sprintf((char*)number_buffer, "null"); } - else if(d == (double)item->valueint) + else if (d == (double)item->valueint) { length = sprintf((char*)number_buffer, "%d", item->valueint); } @@ -1626,7 +1626,7 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp return false; } *output_pointer++ = ','; - if(output_buffer->format) + if (output_buffer->format) { *output_pointer++ = ' '; } @@ -2446,7 +2446,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, c CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type = cJSON_NULL; } @@ -2457,7 +2457,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type = cJSON_True; } @@ -2468,7 +2468,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type = cJSON_False; } @@ -2479,7 +2479,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type = boolean ? cJSON_True : cJSON_False; } @@ -2490,7 +2490,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type = cJSON_Number; item->valuedouble = num; @@ -2516,11 +2516,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type = cJSON_String; item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); - if(!item->valuestring) + if (!item->valuestring) { cJSON_Delete(item); return NULL; @@ -2566,11 +2566,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type = cJSON_Raw; item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); - if(!item->valuestring) + if (!item->valuestring) { cJSON_Delete(item); return NULL; @@ -2583,7 +2583,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + if (item) { item->type=cJSON_Array; } @@ -2617,7 +2617,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); if (!n) @@ -2625,7 +2625,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) cJSON_Delete(a); return NULL; } - if(!i) + if (!i) { a->child = n; } @@ -2657,15 +2657,15 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber((double)numbers[i]); - if(!n) + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) + if (!i) { a->child = n; } @@ -2697,15 +2697,15 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) + for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber(numbers[i]); - if(!n) + n = cJSON_CreateNumber(numbers[i], dec); + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) + if (!i) { a->child = n; } @@ -2740,12 +2740,12 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateString(strings[i]); - if(!n) + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) + if (!i) { a->child = n; } @@ -2818,7 +2818,7 @@ cJSON * cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse) child = item->child; while (child != NULL) { - if(depth >= CJSON_CIRCULAR_LIMIT) { + if (depth >= CJSON_CIRCULAR_LIMIT) { goto fail; } newchild = cJSON_Duplicate_rec(child, depth + 1, true); /* Duplicate (with recurse) each item in the ->next chain */ diff --git a/cJSON.h b/cJSON.h index 37520bbc..7a228eb7 100644 --- a/cJSON.h +++ b/cJSON.h @@ -124,9 +124,9 @@ typedef struct cJSON typedef struct cJSON_Hooks { - /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ - void *(CJSON_CDECL *malloc_fn)(size_t sz); - void (CJSON_CDECL *free_fn)(void *ptr); + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void (CJSON_CDECL *free_fn)(void *ptr); } cJSON_Hooks; typedef int cJSON_bool; @@ -261,7 +261,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); /* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. - * The input pointer json cannot point to a read-only address area, such as a string constant, + * The input pointer json cannot point to a read-only address area, such as a string constant, * but should point to a readable and writable address area. */ CJSON_PUBLIC(void) cJSON_Minify(char *json); diff --git a/cJSON_Utils.c b/cJSON_Utils.c index 63651dfb..7d4a71c3 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -97,7 +97,7 @@ static int compare_strings(const unsigned char *string1, const unsigned char *st return strcmp((const char*)string1, (const char*)string2); } - for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { if (*string1 == '\0') { @@ -147,7 +147,7 @@ static cJSON_bool compare_pointers(const unsigned char *name, const unsigned cha if (((*pointer != 0) && (*pointer != '/')) != (*name != 0)) { /* one string has ended, the other not */ - return false;; + return false; } return true;