cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit e1eb06fae0365d1bb05a3297befe50a0e7e2811a
parent 6aefa450563aaa1720608b2bb83c400e9e99f927
Author: Max Bruckner <max@maxbruckner.de>
Date:   Wed, 30 Nov 2016 22:12:16 +0700

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.

Diffstat:
McJSON.h | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/cJSON.h b/cJSON.h @@ -117,7 +117,10 @@ 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 */ +/* 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. */ extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); extern void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);