From 9f1973c0e7da08af9eab2688ef8eb4a65893caa6 Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Thu, 30 Apr 2026 02:46:18 +0300 Subject: [PATCH] up: fix format types for protection from integer overflow --- libupower-glib/up-device.c | 10 +++++----- libupower-glib/up-history-item.c | 2 +- src/linux/up-device-wup.c | 2 +- src/up-daemon.c | 2 +- src/up-device.c | 4 ++-- src/up-history.c | 10 +++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libupower-glib/up-device.c b/libupower-glib/up-device.c index 1773f1d..1bce207 100644 --- a/libupower-glib/up-device.c +++ b/libupower-glib/up-device.c @@ -212,7 +212,7 @@ up_device_to_text_history (UpDevice *device, GString *string, const gchar *type) g_string_append_printf (string, " History (%s):\n", type); for (i=0; ilen; i++) { item = (UpHistoryItem *) g_ptr_array_index (array, i); - g_string_append_printf (string, " %i\t%.3f\t%s\n", + g_string_append_printf (string, " %u\t%.3f\t%s\n", up_history_item_get_time (item), up_history_item_get_value (item), up_device_state_to_string (up_history_item_get_state (item))); @@ -413,9 +413,9 @@ up_device_to_text (UpDevice *device) if (up_exported_device_get_technology (priv->proxy_device) != UP_DEVICE_TECHNOLOGY_UNKNOWN) g_string_append_printf (string, " technology: %s\n", up_device_technology_to_string (up_exported_device_get_technology (priv->proxy_device))); if (up_exported_device_get_charge_start_threshold (priv->proxy_device) > 0) - g_string_append_printf (string, " charge-start-threshold: %d%%\n", up_exported_device_get_charge_start_threshold (priv->proxy_device)); + g_string_append_printf (string, " charge-start-threshold: %u%%\n", up_exported_device_get_charge_start_threshold (priv->proxy_device)); if (up_exported_device_get_charge_end_threshold (priv->proxy_device) > 0) - g_string_append_printf (string, " charge-end-threshold: %d%%\n", up_exported_device_get_charge_end_threshold (priv->proxy_device)); + g_string_append_printf (string, " charge-end-threshold: %u%%\n", up_exported_device_get_charge_end_threshold (priv->proxy_device)); if (up_exported_device_get_charge_threshold_enabled (priv->proxy_device)) g_string_append_printf (string, " charge-threshold-enabled: %s\n", up_device_bool_to_string (up_exported_device_get_charge_threshold_enabled (priv->proxy_device))); if (up_exported_device_get_charge_threshold_supported (priv->proxy_device)) @@ -499,7 +499,7 @@ up_device_get_history_sync (UpDevice *device, const gchar *type, guint timespec, NULL, &error_local); if (!ret) { - g_set_error (error, 1, 0, "GetHistory(%s,%i) on %s failed: %s", type, timespec, + g_set_error (error, 1, 0, "GetHistory(%s,%u) on %s failed: %s", type, timespec, up_device_get_object_path (device), error_local->message); g_error_free (error_local); goto out; @@ -778,7 +778,7 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe if (v) g_value_copy (v, value); else - g_warning ("Property ID '%s' (%d) was never set", pspec->name, prop_id); + g_warning ("Property ID '%s' (%u) was never set", pspec->name, prop_id); return; } diff --git a/libupower-glib/up-history-item.c b/libupower-glib/up-history-item.c index e87b8c0..14e8ba6 100644 --- a/libupower-glib/up-history-item.c +++ b/libupower-glib/up-history-item.c @@ -184,7 +184,7 @@ gchar * up_history_item_to_string (UpHistoryItem *history_item) { g_return_val_if_fail (UP_IS_HISTORY_ITEM (history_item), NULL); - return g_strdup_printf ("%i\t%.3f\t%s", + return g_strdup_printf ("%u\t%.3f\t%s", history_item->priv->time, history_item->priv->value, up_device_state_to_string (history_item->priv->state)); diff --git a/src/linux/up-device-wup.c b/src/linux/up-device-wup.c index 3adbaa7..8335f63 100644 --- a/src/linux/up-device-wup.c +++ b/src/linux/up-device-wup.c @@ -243,7 +243,7 @@ up_device_wup_parse_command (UpDeviceWup *wup, const gchar *data) /* check the length matches what data we've got*/ size = atoi (tokens[2]); if (size != number_tokens - offset) { - g_debug ("size expected to be '%i' but got '%i'", number_tokens - offset, size); + g_debug ("size expected to be '%u' but got '%u'", number_tokens - offset, size); goto out; } diff --git a/src/up-daemon.c b/src/up-daemon.c index 38d49d5..abb9e5a 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -270,7 +270,7 @@ up_daemon_update_display_battery (UpDaemon *daemon) if (num_batteries <= 1) goto out; - g_debug ("Calculating percentage and time to full/to empty for %i batteries", num_batteries); + g_debug ("Calculating percentage and time to full/to empty for %u batteries", num_batteries); /* use percentage weighted for each battery capacity * fall back to averaging the batteries. diff --git a/src/up-device.c b/src/up-device.c index 2a5ff1a..3b4de18 100644 --- a/src/up-device.c +++ b/src/up-device.c @@ -334,7 +334,7 @@ up_device_get_id (UpDevice *device) } if (up_exported_device_get_energy_full_design (skeleton) > 0) { /* FIXME: this may not be stable if we are using voltage_now */ - g_string_append_printf (string, "%i", (guint) up_exported_device_get_energy_full_design (skeleton)); + g_string_append_printf (string, "%u", (guint) up_exported_device_get_energy_full_design (skeleton)); g_string_append_c (string, '-'); } if (serial != NULL && strlen (serial) > 2) { @@ -617,7 +617,7 @@ up_device_get_statistics (UpExportedDevice *skeleton, if (array->len != 101) { g_dbus_method_invocation_return_error (invocation, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, - "statistics invalid as have %i items", array->len); + "statistics invalid as have %u items", array->len); goto out; } diff --git a/src/up-history.c b/src/up-history.c index 2f53765..3b3301d 100644 --- a/src/up-history.c +++ b/src/up-history.c @@ -132,7 +132,7 @@ up_history_array_limit_resolution (GPtrArray *array, guint max_num) guint step = 1; new = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); - g_debug ("length of array (before) %i", array->len); + g_debug ("length of array (before) %u", array->len); /* check length */ length = array->len; @@ -191,7 +191,7 @@ up_history_array_limit_resolution (GPtrArray *array, guint max_num) } /* check length */ - g_debug ("length of array (after) %i", new->len); + g_debug ("length of array (after) %u", new->len); out: return new; } @@ -220,7 +220,7 @@ up_history_copy_array_timespan (const GPtrArray *array, guint timespan) /* new data */ array_new = g_ptr_array_new (); time_now = g_get_real_time (); - g_debug ("limiting data to last %i seconds", timespan); + g_debug ("limiting data to last %u seconds", timespan); /* treat the timespan like a range, and search backwards */ timespan *= 0.95f; @@ -462,7 +462,7 @@ up_history_array_to_file (UpHistory *history, GPtrArray *list, const gchar *file part = g_string_free (string, FALSE); /* how many did we kill? */ - g_debug ("culled %i of %i", cull_count, list->len); + g_debug ("culled %u of %u", cull_count, list->len); /* we failed to convert to string */ if (!ret) { @@ -526,7 +526,7 @@ up_history_array_from_file (GPtrArray *list, const gchar *filename) } /* add valid entries */ - g_debug ("loading %i items of data from %s", length, filename); + g_debug ("loading %u items of data from %s", length, filename); for (i=0; i