diff options
author | Richard Hughes <richard@hughsie.com> | 2014-06-13 09:48:14 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-06-13 09:48:53 +0100 |
commit | 5c661f0920941ff2a81f9eca3ee9b7295e4044d8 (patch) | |
tree | 28892e2585aebe68cf6d5a5cd5e015eff59e2505 | |
parent | 255a5b600f3b9d6c9b7b18a5a0251114b86cfe3d (diff) | |
download | appstream-glib-5c661f0920941ff2a81f9eca3ee9b7295e4044d8.tar.gz |
Allow as_node_get_attribute_as_int() to parse negative numbers
This was failing as the gint64 value was being pushed into a guint64, so
negative numbers were being pushed above G_MAXINT and hence an error was being
returned.
Additionally, return G_MAXINT rather than G_MAXUINT, else we can't actually
parse the '-1' value.
-rw-r--r-- | libappstream-glib/as-app.c | 4 | ||||
-rw-r--r-- | libappstream-glib/as-image.c | 4 | ||||
-rw-r--r-- | libappstream-glib/as-node.c | 12 | ||||
-rw-r--r-- | libappstream-glib/as-screenshot.c | 4 |
4 files changed, 12 insertions, 12 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index a56a0f9..2073167 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -2175,7 +2175,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, GError **error) if (as_node_get_tag (c) != AS_TAG_LANG) continue; percent = as_node_get_attribute_as_int (c, "percentage"); - if (percent == G_MAXUINT) + if (percent == G_MAXINT) percent = 0; as_app_add_language (app, percent, as_node_get_data (c), -1); @@ -2230,7 +2230,7 @@ as_app_node_parse (AsApp *app, GNode *node, GError **error) if (tmp != NULL) as_app_set_id_kind (app, as_id_kind_from_string (tmp)); prio = as_node_get_attribute_as_int (node, "priority"); - if (prio != G_MAXUINT && prio != 0) + if (prio != G_MAXINT && prio != 0) as_app_set_priority (app, prio); } diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c index 0f8ea13..65aad6a 100644 --- a/libappstream-glib/as-image.c +++ b/libappstream-glib/as-image.c @@ -421,10 +421,10 @@ as_image_node_parse (AsImage *image, GNode *node, GError **error) guint size; size = as_node_get_attribute_as_int (node, "width"); - if (size != G_MAXUINT) + if (size != G_MAXINT) as_image_set_width (image, size); size = as_node_get_attribute_as_int (node, "height"); - if (size != G_MAXUINT) + if (size != G_MAXINT) as_image_set_height (image, size); tmp = as_node_get_attribute (node, "type"); if (tmp != NULL) diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c index b67c4cb..4f57fdc 100644 --- a/libappstream-glib/as-node.c +++ b/libappstream-glib/as-node.c @@ -1001,7 +1001,7 @@ as_node_take_data (const GNode *node) * * Gets a node attribute, e.g. 34 * - * Return value: integer value + * Return value: integer value, or %G_MAXINT for error * * Since: 0.1.0 **/ @@ -1010,16 +1010,16 @@ as_node_get_attribute_as_int (const GNode *node, const gchar *key) { const gchar *tmp; gchar *endptr = NULL; - guint64 value_tmp; + gint64 value_tmp; tmp = as_node_get_attribute (node, key); if (tmp == NULL) - return G_MAXUINT; + return G_MAXINT; value_tmp = g_ascii_strtoll (tmp, &endptr, 10); if (value_tmp == 0 && tmp == endptr) - return G_MAXUINT; - if (value_tmp > G_MAXINT) - return G_MAXUINT; + return G_MAXINT; + if (value_tmp > G_MAXINT || value_tmp < G_MININT) + return G_MAXINT; return value_tmp; } diff --git a/libappstream-glib/as-screenshot.c b/libappstream-glib/as-screenshot.c index 454c241..e9bf506 100644 --- a/libappstream-glib/as-screenshot.c +++ b/libappstream-glib/as-screenshot.c @@ -357,10 +357,10 @@ as_screenshot_node_parse (AsScreenshot *screenshot, GNode *node, GError **error) image = as_image_new (); as_image_set_kind (image, AS_IMAGE_KIND_SOURCE); size = as_node_get_attribute_as_int (node, "width"); - if (size != G_MAXUINT) + if (size != G_MAXINT) as_image_set_width (image, size); size = as_node_get_attribute_as_int (node, "height"); - if (size != G_MAXUINT) + if (size != G_MAXINT) as_image_set_height (image, size); as_image_set_url (image, tmp, -1); g_ptr_array_add (priv->images, image); |