From a954525ca87193e1a7c840fa71172f2310d1bea1 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 10 Mar 2021 15:38:40 +0900 Subject: [PATCH] Add NULL checking to prevent dereferenced problem. Change-Id: I6ff1a170342dd25822739dc0d4f11ff95c43e492 Signed-off-by: Joonbum Ko --- samples/tri.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/samples/tri.c b/samples/tri.c index b42cd55..b3986d6 100644 --- a/samples/tri.c +++ b/samples/tri.c @@ -1789,16 +1789,18 @@ static const struct wl_shell_surface_listener shell_surface_listener = { static void demo_create_window(struct demo *demo) { demo->wl_surface = wl_compositor_create_surface(demo->compositor); - demo->shell_surface = wl_shell_get_shell_surface(demo->shell, demo->wl_surface); + if (demo->wl_surface) { + demo->shell_surface = wl_shell_get_shell_surface(demo->shell, demo->wl_surface); - if (demo->shell_surface) { - wl_shell_surface_add_listener(demo->shell_surface, - &shell_surface_listener, demo); - wl_shell_surface_set_toplevel(demo->shell_surface); - wl_shell_surface_set_title(demo->shell_surface, APP_SHORT_NAME); - } + if (demo->shell_surface) { + wl_shell_surface_add_listener(demo->shell_surface, + &shell_surface_listener, demo); + wl_shell_surface_set_toplevel(demo->shell_surface); + wl_shell_surface_set_title(demo->shell_surface, APP_SHORT_NAME); + } - wl_surface_set_user_data(demo->wl_surface, demo); + wl_surface_set_user_data(demo->wl_surface, demo); + } } #endif // _WIN32 -- 2.7.4