diff options
author | Richard Hughes <richard@hughsie.com> | 2014-05-12 15:53:26 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-05-12 15:53:33 +0100 |
commit | 5583c207f9c6ea2cd838bcba4ec3f8e3c9f2955a (patch) | |
tree | 0bcb1f35075712bfb6effb131c0db2a89829064d /client | |
parent | 04edd1ec8a06a1d3c2999c763c150ecbdf2845bf (diff) | |
download | appstream-glib-5583c207f9c6ea2cd838bcba4ec3f8e3c9f2955a.tar.gz |
Don't crash when doing 'appstream-util status-html' on an empty XML file
Diffstat (limited to 'client')
-rw-r--r-- | client/as-util.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/client/as-util.c b/client/as-util.c index 0b89448..f9145b4 100644 --- a/client/as-util.c +++ b/client/as-util.c @@ -768,11 +768,14 @@ as_util_status_html_write_app (AsApp *app, GString *html) /** * as_util_status_html_write_exec_summary: */ -static void -as_util_status_html_write_exec_summary (GPtrArray *apps, GString *html) +static gboolean +as_util_status_html_write_exec_summary (GPtrArray *apps, + GString *html, + GError **error) { AsApp *app; const gchar *project_groups[] = { "GNOME", "KDE", "XFCE", NULL }; + gboolean ret = TRUE; guint cnt; guint i; guint j; @@ -788,6 +791,14 @@ as_util_status_html_write_exec_summary (GPtrArray *apps, GString *html) if (as_app_get_id_kind (app) == AS_ID_KIND_DESKTOP) total++; } + if (total == 0) { + ret = FALSE; + g_set_error_literal (error, + AS_ERROR, + AS_ERROR_INVALID_ARGUMENTS, + "No desktop applications found"); + goto out; + } /* long descriptions */ cnt = 0; @@ -863,6 +874,8 @@ as_util_status_html_write_exec_summary (GPtrArray *apps, GString *html) project_groups[j], cnt, perc); } g_string_append (html, "</ul>\n"); +out: + return ret; } /** @@ -912,8 +925,11 @@ as_util_status_html (AsUtilPrivate *priv, gchar **values, GError **error) g_string_append (html, "<body>\n"); /* summary section */ - if (apps->len > 0) - as_util_status_html_write_exec_summary (apps, html); + if (apps->len > 0) { + ret = as_util_status_html_write_exec_summary (apps, html, error); + if (!ret) + goto out; + } /* write applications */ g_string_append (html, "<h1>Applications</h1>\n"); |