summaryrefslogtreecommitdiff
path: root/json_object.c
diff options
context:
space:
mode:
authorEric Haszlakiewicz <erh+git@nimenees.com>2016-10-29 15:42:36 -0400
committerEric Haszlakiewicz <erh+git@nimenees.com>2016-10-29 15:42:36 -0400
commitd4899bd4d58eff3b2e05dfe59c0604e46a6fb546 (patch)
tree1418c5145ad3958e3d7aca0a65d4c80b316e4748 /json_object.c
parentf8132f932dd3ab26e7e93b23b18efc00a16f898c (diff)
downloadjson-c-d4899bd4d58eff3b2e05dfe59c0604e46a6fb546.tar.gz
Handle NULL objects in json_object_get_userdata() by returning NULL, but abort in json_object_set_userdata() since we can't actually do anything with the userdata.
Diffstat (limited to 'json_object.c')
-rw-r--r--json_object.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/json_object.c b/json_object.c
index 939eae6..8a70b5d 100644
--- a/json_object.c
+++ b/json_object.c
@@ -241,12 +241,15 @@ enum json_type json_object_get_type(const struct json_object *jso)
}
void* json_object_get_userdata(json_object *jso) {
- return jso->_userdata;
+ return jso ? jso->_userdata : NULL;
}
void json_object_set_userdata(json_object *jso, void *userdata,
json_object_delete_fn *user_delete)
{
+ // Can't return failure, so abort if we can't perform the operation.
+ assert(jso != NULL);
+
// First, clean up any previously existing user info
if (jso->_user_delete)
jso->_user_delete(jso, jso->_userdata);