cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

added const to cJSON_AddItemReferenceTo* item argument

Open mdvorak opened this issue 4 years ago • 1 comments

Referenced object should never be modified. Internally, create_reference takes const cJSON* item anyway, and making this parameter const is on par with cJSON_CreateObjectReference, which also have const cJSON* child argument.

Typical use-case:

void my_function(const cJSON* obj)
{
  cJSON* wrapper = cJSON_CreateObject();
  cJSON_AddItemReferenceToObject(wrapper, "foobar", obj); // <--- this fails atm, const needs to be cast away
  // ... do something
  cJSON_Delete(wrapper);
}

mdvorak avatar Feb 24 '21 11:02 mdvorak

This would be really nice to get merged.

bullestock avatar Sep 16 '23 09:09 bullestock