-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
Labels
Milestone
Description
Hi,
I have a problem with the cJSON_Add[*]ToObject functions.
For example, when using the cJSON_AddStringToObject macro (which uses cJSON_AddItemToObject), I can't be sure that it succeeded.
The problem is that cJSON_CreateString returns NULL in case of error, but cJSON_AddItemToObject ignores the NULL item without any action. My suggestion (in case someone is interested!) would be to add a return value to cJSON_AddItemToObject and similar functions (for example, let cJSON_AddItemToObject return item). In this case, I can write this code:
if (!cJSON_AddStringToObject(obj, "nombre", "pepito")) {
... failed, do something ...
}
Bottom line, the return value of cJSON_Create[*] is thrown away, and the library's user is never informed if the operations succeeded or not. What do you think?
Regards,
Diego.
Reactions are currently unavailable