[Xfce4-commits] [xfce/xfce4-power-manager] 01/03: Don't crash when UPower returns "" for the icon-name (Bug #11756)

noreply at xfce.org noreply at xfce.org
Sun Mar 29 14:45:07 CEST 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit f6c58f4520f36c5cab3e3192bf3f9b6d4ec21cdb
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Sat Mar 28 10:59:18 2015 +0300

    Don't crash when UPower returns "" for the icon-name (Bug #11756)
    
    I assume this is for devices UPower doesn't know anything about?
---
 common/xfpm-power-common.c                         |   15 +++++++++++--
 .../power-manager-plugin/power-manager-button.c    |   23 +++++++++++---------
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/common/xfpm-power-common.c b/common/xfpm-power-common.c
index 43fc731..c9df21e 100644
--- a/common/xfpm-power-common.c
+++ b/common/xfpm-power-common.c
@@ -29,6 +29,7 @@
 #include "xfpm-enum-glib.h"
 
 #include "xfpm-icons.h"
+#include "xfpm-debug.h"
 
 
 /**
@@ -176,7 +177,17 @@ get_device_icon_name (UpClient *upower, UpDevice *device)
     /* Strip away the symbolic suffix for the device icons for the devices tab
      * and the panel plugin's menu */
     icon_suffix = g_strrstr (upower_icon, "-symbolic");
-    icon_base_length = icon_suffix - upower_icon;
+    if (icon_suffix != NULL)
+    {
+        icon_base_length = icon_suffix - upower_icon;
+    }
+    else
+    {
+        icon_base_length = G_MAXINT;
+    }
+
+    XFPM_DEBUG ("icon_suffix %s, icon_base_length %ld, upower_icon %s",
+                icon_suffix, icon_base_length, upower_icon);
 
     /* mapped from
      * http://cgit.freedesktop.org/upower/tree/libupower-glib/up-types.h
@@ -202,7 +213,7 @@ get_device_icon_name (UpClient *upower, UpDevice *device)
         icon_name = g_strdup (XFPM_TABLET_ICON);
     else if ( type == UP_DEVICE_KIND_COMPUTER )
         icon_name = g_strdup (XFPM_COMPUTER_ICON);
-    else
+    else if ( g_strcmp0 (upower_icon, "") != 0 )
         icon_name = g_strndup (upower_icon, icon_base_length);
 
     return icon_name;
diff --git a/panel-plugins/power-manager-plugin/power-manager-button.c b/panel-plugins/power-manager-plugin/power-manager-button.c
index 9749a13..1f3b9e2 100644
--- a/panel-plugins/power-manager-plugin/power-manager-button.c
+++ b/panel-plugins/power-manager-plugin/power-manager-button.c
@@ -37,6 +37,7 @@
 #include "common/xfpm-icons.h"
 #include "common/xfpm-power-common.h"
 #include "common/xfpm-brightness.h"
+#include "common/xfpm-debug.h"
 
 #include "power-manager-button.h"
 #include "scalemenuitem.h"
@@ -361,10 +362,10 @@ power_manager_button_update_device_icon_and_details (PowerManagerButton *button,
     BatteryDevice *battery_device, *display_device;
     const gchar *object_path = up_device_get_object_path(device);
     gchar *details, *icon_name, *upower_icon;
-    GdkPixbuf *pix;
+    GdkPixbuf *pix = NULL;
     guint type = 0;
 
-    TRACE("entering for %s", object_path);
+    XFPM_DEBUG("entering for %s", object_path);
 
     if (!POWER_MANAGER_IS_BUTTON (button))
         return;
@@ -385,13 +386,15 @@ power_manager_button_update_device_icon_and_details (PowerManagerButton *button,
     icon_name = get_device_icon_name (button->priv->upower, device);
     details = get_device_description (button->priv->upower, device);
 
-    pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
-				                    icon_name,
-				                    32,
-				                    GTK_ICON_LOOKUP_USE_BUILTIN,
-				                    NULL);
-
-    g_free (icon_name);
+    if (icon_name)
+    {
+        pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+                                        icon_name,
+                                        32,
+                                        GTK_ICON_LOOKUP_USE_BUILTIN,
+                                        NULL);
+        g_free (icon_name);
+    }
 
     if (battery_device->details)
 	g_free (battery_device->details);
@@ -448,7 +451,7 @@ power_manager_button_add_device (UpDevice *device, PowerManagerButton *button)
     const gchar *object_path = up_device_get_object_path(device);
     gulong signal_id;
 
-    TRACE("entering for %s", object_path);
+    XFPM_DEBUG("entering for %s", object_path);
 
     g_return_if_fail (POWER_MANAGER_IS_BUTTON (button ));
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list