[PATCH] desktop-shell: don't segfault on invalid icon path

Philipp Brüschweiler blei42 at gmail.com
Tue Aug 28 10:10:18 PDT 2012


Instead load a fallback icon and proceed as normal.

https://bugs.freedesktop.org/show_bug.cgi?id=53860
---
 clients/desktop-shell.c | 19 ++++++++++++++++++-
 1 Datei geändert, 18 Zeilen hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index dc87e75..fe8fe02 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -472,6 +472,23 @@ panel_create(struct display *display)
 	return panel;
 }
 
+static cairo_surface_t *
+load_icon_or_fallback(const char *icon)
+{
+	cairo_surface_t *surface = cairo_image_surface_create_from_png(icon);
+
+	if (cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS)
+		return surface;
+
+	fprintf(stderr, "ERROR loading icon from file '%s'\n", icon);
+
+	// loading fallback
+	surface = cairo_image_surface_create_from_png(
+	    DATADIR "/weston/icon_window.png");
+
+	return surface;
+}
+
 static void
 panel_add_launcher(struct panel *panel, const char *icon, const char *path)
 {
@@ -481,7 +498,7 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
 
 	launcher = malloc(sizeof *launcher);
 	memset(launcher, 0, sizeof *launcher);
-	launcher->icon = cairo_image_surface_create_from_png(icon);
+	launcher->icon = load_icon_or_fallback(icon);
 	launcher->path = strdup(path);
 
 	wl_array_init(&launcher->envp);
-- 
1.7.12



More information about the wayland-devel mailing list