This commit is contained in:
Roy van der Vegt 2016-10-31 01:38:57 +00:00 committed by GitHub
commit bcc0e26643
3 changed files with 16 additions and 13 deletions

View File

@ -43,9 +43,9 @@ install (FILES cJSON_Utils.h DESTINATION include/cJSON)
option(ENABLE_CJSON_TEST "Enable building cJSON test" OFF)
if(ENABLE_CJSON_TEST)
set(TEST_CJSON cJSON_test)
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" )
add_executable(${TEST_CJSON} test.c)
target_link_libraries(${TEST_CJSON} ${PROJ_CJSON}.shared)
set(TEST_CJSON_UTILS cJSON_test_utils)
add_executable(${TEST_CJSON_UTILS} test_utils.c)
target_link_libraries(${TEST_CJSON_UTILS} ${PROJ_CJSON_UTILS}.shared)

View File

@ -116,7 +116,7 @@ void cJSON_Delete(cJSON *c)
{
cJSON_Delete(c->child);
}
if (!(c->type & cJSON_IsReference) && c->valuestring)
if ((c->type & cJSON_String) && !(c->type & cJSON_IsReference) && c->valuestring)
{
cJSON_free(c->valuestring);
}
@ -899,7 +899,7 @@ static const char *parse_value(cJSON *item, const char *value, const char **ep)
return parse_object(item, value, ep);
}
*ep=value;return 0; /* failure. */
*ep=value;return 0; /* failure. */
}
/* Render a value to text. */

23
cJSON.h
View File

@ -52,12 +52,15 @@ typedef struct cJSON
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String */
char *valuestring;
/* The item's number, if type==cJSON_Number */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
union
{
/* The item's string, if type==cJSON_String */
char *valuestring;
/* The item's number, if type==cJSON_Number */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
};
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
@ -85,7 +88,7 @@ extern char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, int fmt);
extern void cJSON_Delete(cJSON *c);
/* Returns the number of items in an array (or object). */
extern int cJSON_GetArraySize(const cJSON *array);
extern int cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
extern cJSON *cJSON_GetArrayItem(const cJSON *array, int item);
/* Get item "string" from object. Case insensitive. */
@ -112,11 +115,11 @@ extern cJSON *cJSON_CreateStringArray(const char **strings, int count);
/* Append item to the specified array/object. */
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
extern void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object */
extern void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
extern void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object */
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
extern void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detatch items from Arrays/Objects. */
extern cJSON *cJSON_DetachItemFromArray(cJSON *array, int which);