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

Scott Moreau oreaus at gmail.com
Tue Aug 28 10:38:50 PDT 2012


Hi Philipp,

I happened across your patch and wanted to comment about the styling. (see
below)

On Tue, Aug 28, 2012 at 11:10 AM, Philipp Brüschweiler <blei42 at gmail.com>wrote:

> 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
>

For comments in weston, we use C style /* Comment here */


> +       surface = cairo_image_surface_create_from_png(
> +           DATADIR "/weston/icon_window.png");
>

You might be able to arrange this differently, such as

surface =
      cairo_image_surface_create_from_png(DATADIR
                  "/weston/icon_window.png");

so you don't have a function(\n.
You can use about 80 characters before starting a new line.

+
> +       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
>
>
Regards,

Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20120828/6f0c5a08/attachment.html>


More information about the wayland-devel mailing list