cJSON.h warn about write access to constants (#80)

Add a comment that warns about potential write access to constant memory
locations after using cJSON_AddItemToObjectCS.
This commit is contained in:
Max Bruckner 2016-11-30 22:12:16 +07:00
parent 6aefa45056
commit e1eb06fae0

View File

@ -117,7 +117,10 @@ extern cJSON *cJSON_CreateStringArray(const char **strings, int count);
/* Append item to the specified array/object. */ /* Append item to the specified array/object. */
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemToObject(cJSON *object, const char *string, 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 */ /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
extern void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* 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. */ /* 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_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);