From 8bb2dc68ea9168553a68eb4df672f87ed667637f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 29 Dec 2019 22:42:23 +0100 Subject: [PATCH] xdg-shell: make wlr_xdg_surface_from_resource reject NULL Most resources must not be NULL. Make it so callers need to check for NULL explicitly. This makes it clearer in the handlers code that the NULL wl_resource case needs to be handled, and allows callers to make a difference between a NULL wl_resource and an inert resource. --- types/xdg_shell/wlr_xdg_surface.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index c3ea9f44..eb68c14c 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -237,8 +237,10 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, struct wl_resource *positioner_resource) { struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_from_resource(resource); - struct wlr_xdg_surface *parent = - wlr_xdg_surface_from_resource(parent_resource); + struct wlr_xdg_surface *parent = NULL; + if (parent_resource != NULL) { + parent = wlr_xdg_surface_from_resource(parent_resource); + } if (xdg_surface == NULL) { return; // TODO: create an inert xdg_popup } @@ -517,9 +519,6 @@ void destroy_xdg_surface(struct wlr_xdg_surface *surface) { struct wlr_xdg_surface *wlr_xdg_surface_from_resource( struct wl_resource *resource) { - if (!resource) { - return NULL; - } assert(wl_resource_instance_of(resource, &xdg_surface_interface, &xdg_surface_implementation)); return wl_resource_get_user_data(resource);