From e1eb06fae0365d1bb05a3297befe50a0e7e2811a Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 30 Nov 2016 22:12:16 +0700 Subject: [PATCH] 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. --- cJSON.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cJSON.h b/cJSON.h index 4d015c3..ca79ae9 100644 --- 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);