From 7dda25b2d5ec6e79561d9e558b21e0230166605b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20Krezovi=C4=87?= Date: Thu, 23 Jun 2016 11:59:31 +0200 Subject: [PATCH] toytoolkit: Return NULL when no outputs are present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, display_get_output returns a first member of the linked list, which can never be NULL. This is problematic, as the function would return a dangling pointer and NULL pointer checks wouldn't work where needed and some of the invalid members would get accessed that way, resulting in a crash. Reviewed-by: Quentin Glidic Reviewed-by: Pekka Paalanen Signed-off-by: Armin Krezović --- clients/window.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clients/window.c b/clients/window.c index b5b598f4..4de73ed2 100644 --- a/clients/window.c +++ b/clients/window.c @@ -5845,6 +5845,9 @@ display_get_cairo_device(struct display *display) struct output * display_get_output(struct display *display) { + if (wl_list_empty(&display->output_list)) + return NULL; + return container_of(display->output_list.next, struct output, link); }