[notification-daemon] fix crash in nd_notification_get_is_transient
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [notification-daemon] fix crash in nd_notification_get_is_transient
- Date: Thu, 30 Oct 2014 14:32:49 +0000 (UTC)
commit 2286ebc37381f8e2d1f5260ebd29d890e2d024ef
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Oct 30 16:13:51 2014 +0200
fix crash in nd_notification_get_is_transient
It is error to call g_variant_get_boolean on types other than
G_VARIANT_TYPE_BOOLEAN. Fix this by converting values to boolean.
1) G_VARIANT_TYPE_INT32: 0 == FALSE, any other value == TRUE
2) G_VARIANT_TYPE_DOUBLE: 0 == FALSE, any other value == TRUE
3) G_VARIANT_TYPE_STRING: TRUE
4) G_VARIANT_TYPE_BYTE: 0 == FALSE, any other value == TRUE
This is based on patch that is attached in debian bug, link
available in bug report.
https://bugzilla.gnome.org/show_bug.cgi?id=665166
src/nd-notification.c | 58 ++++++++++++++++++++++---------------------------
1 files changed, 26 insertions(+), 32 deletions(-)
---
diff --git a/src/nd-notification.c b/src/nd-notification.c
index 05372d0..29cf6a4 100644
--- a/src/nd-notification.c
+++ b/src/nd-notification.c
@@ -223,55 +223,49 @@ nd_notification_get_is_closed (NdNotification *notification)
return notification->is_closed;
}
-gboolean
-nd_notification_get_is_transient (NdNotification *notification)
+static gboolean
+hint_to_boolean (NdNotification *notification,
+ const gchar *hint_name)
{
- gboolean ret;
GVariant *value;
- ret = FALSE;
g_return_val_if_fail (ND_IS_NOTIFICATION (notification), FALSE);
- value = g_hash_table_lookup (notification->hints, "transient");
- if (value != NULL) {
- ret = g_variant_get_boolean (value);
+ value = g_hash_table_lookup (notification->hints, hint_name);
+ if (value == NULL)
+ return FALSE;
+
+ if (g_variant_is_of_type (value, G_VARIANT_TYPE_INT32)) {
+ return (g_variant_get_int32 (value) != 0);
+ } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_DOUBLE)) {
+ return (g_variant_get_double (value) != 0);
+ } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) {
+ return TRUE;
+ } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_BYTE)) {
+ return (g_variant_get_byte (value) != 0);
+ } else {
+ g_assert_not_reached ();
}
- return ret;
+ return FALSE;
}
gboolean
-nd_notification_get_is_resident (NdNotification *notification)
+nd_notification_get_is_transient (NdNotification *notification)
{
- gboolean ret;
- GVariant *value;
-
- ret = FALSE;
- g_return_val_if_fail (ND_IS_NOTIFICATION (notification), FALSE);
-
- value = g_hash_table_lookup (notification->hints, "resident");
- if (value != NULL) {
- ret = g_variant_get_boolean (value);
- }
+ return hint_to_boolean (notification, "transient");
+}
- return ret;
+gboolean
+nd_notification_get_is_resident (NdNotification *notification)
+{
+ return hint_to_boolean (notification, "resident");
}
gboolean
nd_notification_get_action_icons (NdNotification *notification)
{
- gboolean ret;
- GVariant *value;
-
- ret = FALSE;
- g_return_val_if_fail (ND_IS_NOTIFICATION (notification), FALSE);
-
- value = g_hash_table_lookup (notification->hints, "action-icons");
- if (value != NULL) {
- ret = g_variant_get_boolean (value);
- }
-
- return ret;
+ return hint_to_boolean (notification, "action-icons");
}
guint32
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]