]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Handle NULL objects in json_object_get_userdata() by returning NULL, but abort in...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 29 Oct 2016 19:42:36 +0000 (15:42 -0400)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 29 Oct 2016 19:42:36 +0000 (15:42 -0400)
json_object.c

index 939eae667a07bbf76f32bbf8abf9814a9444e1ed..8a70b5d28077ec5a21c6553bf72a76afa1a45950 100644 (file)
@@ -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);