1 From 6189440308723dd72fa9a97a0f19db34083c95a9 Mon Sep 17 00:00:00 2001
2 From: Eric Koegel <eric.koegel@gmail.com>
3 Date: Tue, 29 Apr 2014 08:00:17 +0300
4 Subject: [PATCH 203/219] Fix uninitialized pointer read
6 The tip pointer could be used uninitialized when the device state
7 is unknown. Also tooltips are now shown for all device types rather
8 than just UPS and battery (i.e. for the mouse/keyboard icons). This
9 should prevent some confustion over what the other icons represent.
11 src/xfpm-battery.c | 33 ++++++++++++++++++++++-----------
12 1 file changed, 22 insertions(+), 11 deletions(-)
14 diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
15 index 603c8de..3a246ad 100644
16 --- a/src/xfpm-battery.c
17 +++ b/src/xfpm-battery.c
18 @@ -405,16 +405,25 @@ xfpm_battery_notify_state (XfpmBattery *battery)
22 - * Refresh tooltip function for UPS and battery device only.
23 + * Refresh tooltip function for devices with a battery.
26 xfpm_battery_set_tooltip_primary (XfpmBattery *battery, GtkTooltip *tooltip)
30 gchar *est_time_str = NULL;
31 gchar *power_status = NULL;
33 - power_status = g_strdup_printf (battery->priv->ac_online ? _("Adaptor is online") : _("System is running on battery power"));
34 + if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
35 + battery->priv->type == UP_DEVICE_KIND_UPS )
37 + power_status = g_strdup_printf (battery->priv->ac_online ? _("Adaptor is online") : _("System is running on battery power"));
41 + /* Let the user know it's not a system battery being monitored */
42 + power_status = g_strdup(_("Peripheral Device"));
45 if ( battery->priv->state == UP_DEVICE_STATE_FULLY_CHARGED )
47 @@ -489,6 +498,14 @@ xfpm_battery_set_tooltip_primary (XfpmBattery *battery, GtkTooltip *tooltip)
49 tip = g_strdup_printf (_("%s\nYour %s is empty"), power_status, battery->priv->battery_name);
53 + /* unknown device state, just display the percentage */
54 + tip = g_strdup_printf (_("%s\nYour %s is at (%i%%)."),
56 + battery->priv->battery_name,
57 + battery->priv->percentage);
60 gtk_tooltip_set_text (tooltip, tip);
61 g_free (power_status);
62 @@ -592,14 +609,8 @@ xfpm_battery_query_tooltip (GtkStatusIcon *icon,
64 battery = XFPM_BATTERY (icon);
66 - if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
67 - battery->priv->type == UP_DEVICE_KIND_UPS )
69 - xfpm_battery_set_tooltip_primary (battery, tooltip);
74 + xfpm_battery_set_tooltip_primary (battery, tooltip);