aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-13 23:33:16 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-07-13 23:33:16 -0500
commit3f29c1a35113bfd2461dca76235f1812c8dfd6ef (patch)
treef431b2f52e64ddb4999be2f6791c160f24da6470
parent2d06cbb066f9ae0a0a49d5d260ebe28bb17311fc (diff)
downloadayatana-indicator-power-3f29c1a35113bfd2461dca76235f1812c8dfd6ef.tar.gz
ayatana-indicator-power-3f29c1a35113bfd2461dca76235f1812c8dfd6ef.tar.bz2
ayatana-indicator-power-3f29c1a35113bfd2461dca76235f1812c8dfd6ef.zip
fix some compiler warnings generated by clang static analyzer
-rw-r--r--src/device-provider-upower.c10
-rw-r--r--src/device-provider.c2
-rw-r--r--src/device.c18
-rw-r--r--src/ib-brightness-control.c6
-rw-r--r--src/main.c2
-rw-r--r--src/service.c33
-rw-r--r--tests/test-device.cc4
7 files changed, 27 insertions, 48 deletions
diff --git a/src/device-provider-upower.c b/src/device-provider-upower.c
index 7c12beb..400a060 100644
--- a/src/device-provider-upower.c
+++ b/src/device-provider-upower.c
@@ -17,8 +17,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include "dbus-upower.h"
#include "device.h"
#include "device-provider.h"
@@ -60,7 +58,7 @@ G_DEFINE_TYPE_WITH_CODE (
indicator_power_device_provider_upower,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_DEVICE_PROVIDER,
- indicator_power_device_provider_interface_init));
+ indicator_power_device_provider_interface_init))
/***
**** UPOWER DBUS
@@ -102,7 +100,7 @@ on_device_properties_ready (GObject * o, GAsyncResult * res, gpointer gdata)
gdouble percentage = 0;
gint64 time_to_empty = 0;
gint64 time_to_full = 0;
- time_t time;
+ gint64 time;
IndicatorPowerDevice * device;
IndicatorPowerDeviceProviderUPowerPriv * p = data->self->priv;
GVariant * dict = g_variant_get_child_value (response, 0);
@@ -120,7 +118,7 @@ on_device_properties_ready (GObject * o, GAsyncResult * res, gpointer gdata)
INDICATOR_POWER_DEVICE_STATE, (gint)state,
INDICATOR_POWER_DEVICE_OBJECT_PATH, data->path,
INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,
- INDICATOR_POWER_DEVICE_TIME, (guint64)time,
+ INDICATOR_POWER_DEVICE_TIME, time,
NULL);
}
else
@@ -129,7 +127,7 @@ on_device_properties_ready (GObject * o, GAsyncResult * res, gpointer gdata)
kind,
percentage,
state,
- time);
+ (time_t)time);
g_hash_table_insert (p->devices,
g_strdup (data->path),
diff --git a/src/device-provider.c b/src/device-provider.c
index 81a8eec..46fcfad 100644
--- a/src/device-provider.c
+++ b/src/device-provider.c
@@ -29,7 +29,7 @@ static guint signals[SIGNAL_LAST] = { 0 };
G_DEFINE_INTERFACE (IndicatorPowerDeviceProvider,
indicator_power_device_provider,
- 0);
+ 0)
static void
indicator_power_device_provider_default_init (IndicatorPowerDeviceProviderInterface * klass)
diff --git a/src/device.c b/src/device.c
index 8780d72..f37aa7d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -44,8 +44,6 @@ struct _IndicatorPowerDevicePrivate
GTimer * inestimable;
};
-#define INDICATOR_POWER_DEVICE_GET_PRIVATE(o) (INDICATOR_POWER_DEVICE(o)->priv)
-
/* Properties */
/* Enum for the properties so that they can be quickly found and looked up. */
enum {
@@ -69,7 +67,7 @@ static void set_property (GObject*, guint prop_id, const GValue*, GParamSpec* );
static void get_property (GObject*, guint prop_id, GValue*, GParamSpec* );
/* LCOV_EXCL_START */
-G_DEFINE_TYPE (IndicatorPowerDevice, indicator_power_device, G_TYPE_OBJECT);
+G_DEFINE_TYPE (IndicatorPowerDevice, indicator_power_device, G_TYPE_OBJECT)
/* LCOV_EXCL_STOP */
static void
@@ -189,7 +187,7 @@ get_property (GObject * o, guint prop_id, GValue * value, GParamSpec * pspec)
break;
case PROP_TIME:
- g_value_set_uint64 (value, priv->time);
+ g_value_set_uint64 (value, (guint64)priv->time);
break;
default:
@@ -207,11 +205,11 @@ set_property (GObject * o, guint prop_id, const GValue * value, GParamSpec * psp
switch (prop_id)
{
case PROP_KIND:
- p->kind = g_value_get_int (value);
+ p->kind = (UpDeviceKind) g_value_get_int (value);
break;
case PROP_STATE:
- p->state = g_value_get_int (value);
+ p->state = (UpDeviceState) g_value_get_int (value);
break;
case PROP_OBJECT_PATH:
@@ -224,7 +222,7 @@ set_property (GObject * o, guint prop_id, const GValue * value, GParamSpec * psp
break;
case PROP_TIME:
- p->time = g_value_get_uint64(value);
+ p->time = (time_t) g_value_get_uint64(value);
break;
default:
@@ -627,8 +625,8 @@ get_accessible_time_remaining (const IndicatorPowerDevice * device)
if (p->time && ((p->state == UP_DEVICE_STATE_CHARGING) || (p->state == UP_DEVICE_STATE_DISCHARGING)))
{
- int minutes = p->time / 60;
- const int hours = minutes / 60;
+ guint minutes = (guint)p->time / 60u;
+ const guint hours = minutes / 60u;
minutes %= 60;
if (p->state == UP_DEVICE_STATE_CHARGING)
@@ -889,5 +887,5 @@ indicator_power_device_new_from_variant (GVariant * v)
kind,
percentage,
state,
- time);
+ (time_t)time);
}
diff --git a/src/ib-brightness-control.c b/src/ib-brightness-control.c
index 4fb6bc5..67da10c 100644
--- a/src/ib-brightness-control.c
+++ b/src/ib-brightness-control.c
@@ -76,7 +76,7 @@ ib_brightness_control_set_value (IbBrightnessControl* self, gint value)
gint fd;
gchar *filename;
gchar *svalue;
- gint length;
+ size_t length;
gint err;
if (self->path == NULL)
@@ -95,7 +95,7 @@ ib_brightness_control_set_value (IbBrightnessControl* self, gint value)
err = errno;
errno = 0;
- if (write (fd, svalue, length) != length) {
+ if (write (fd, svalue, length) != (ssize_t)length) {
g_warning ("Fail to write brightness information: %s", g_strerror(errno));
}
errno = err;
@@ -105,7 +105,7 @@ ib_brightness_control_set_value (IbBrightnessControl* self, gint value)
g_free (filename);
}
-gint
+static gint
ib_brightness_control_get_value_from_file (IbBrightnessControl *self, const gchar *file)
{
GError *error;
diff --git a/src/main.c b/src/main.c
index ef615dc..7363284 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,8 +17,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <locale.h>
#include <stdlib.h> /* exit() */
diff --git a/src/service.c b/src/service.c
index 6438c9a..7478d0f 100644
--- a/src/service.c
+++ b/src/service.c
@@ -18,8 +18,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <url-dispatcher.h>
@@ -471,7 +469,7 @@ get_brightness_range (IndicatorPowerService * self, gint * low, gint * high)
{
max = ib_brightness_uscreen_control_get_max_value (self->priv->brightness_uscreen_control);
}
- *low = max * 0.05; /* 5% minimum -- don't let the screen go completely dark */
+ *low = (gint)(max * 0.05); /* 5% minimum -- don't let the screen go completely dark */
*high = max;
}
@@ -621,18 +619,6 @@ rebuild_header_now (IndicatorPowerService * self)
rebuild_now (self, SECTION_HEADER);
}
-static inline void
-rebuild_devices_section_now (IndicatorPowerService * self)
-{
- rebuild_now (self, SECTION_DEVICES);
-}
-
-static inline void
-rebuild_settings_section_now (IndicatorPowerService * self)
-{
- rebuild_now (self, SECTION_SETTINGS);
-}
-
static void
create_menu (IndicatorPowerService * self, int profile)
{
@@ -938,7 +924,7 @@ on_devices_changed (IndicatorPowerService * self)
if (p->primary_device == NULL)
battery_level = 0;
else
- battery_level = (int)(indicator_power_device_get_percentage (p->primary_device) + 0.5);
+ battery_level = (guint32)(indicator_power_device_get_percentage (p->primary_device) + 0.5);
g_simple_action_set_state (p->battery_level_action, g_variant_new_uint32 (battery_level));
rebuild_now (self, SECTION_HEADER | SECTION_DEVICES);
@@ -1131,9 +1117,8 @@ indicator_power_service_set_device_provider (IndicatorPowerService * self,
if (p->device_provider != NULL)
{
- g_signal_handlers_disconnect_by_func (p->device_provider,
- G_CALLBACK(on_devices_changed),
- self);
+ g_signal_handlers_disconnect_by_data (p->device_provider, self);
+
g_clear_object (&p->device_provider);
g_clear_object (&p->primary_device);
@@ -1177,13 +1162,13 @@ create_totalled_battery_device (const GList * devices)
for (l=devices; l!=NULL; l=l->next)
{
- const IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE(l->data);
+ const IndicatorPowerDevice * walk = INDICATOR_POWER_DEVICE(l->data);
- if (indicator_power_device_get_kind(device) == UP_DEVICE_KIND_BATTERY)
+ if (indicator_power_device_get_kind(walk) == UP_DEVICE_KIND_BATTERY)
{
- const double percent = indicator_power_device_get_percentage (device);
- const time_t t = indicator_power_device_get_time (device);
- const UpDeviceState state = indicator_power_device_get_state (device);
+ const double percent = indicator_power_device_get_percentage (walk);
+ const time_t t = indicator_power_device_get_time (walk);
+ const UpDeviceState state = indicator_power_device_get_state (walk);
++n_batteries;
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 7d54816..1d10b5b 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -710,10 +710,10 @@ TEST_F(DeviceTest, ChoosePrimary)
std::vector<IndicatorPowerDevice*> devices;
for(const auto& desc : descriptions)
- devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, desc.time));
+ devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, (time_t)desc.time));
const struct {
- std::vector<int> device_indices;
+ std::vector<unsigned> device_indices;
Description expected;
} tests[] = {