Merge branch 'fix-format-types' into 'master'

up: fix format types for protection from integer overflow

See merge request upower/upower!318
This commit is contained in:
Herman Semenov 2026-04-29 11:48:50 -12:00
commit cd93cdd12f
6 changed files with 15 additions and 15 deletions

View file

@ -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; i<array->len; 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;
}

View file

@ -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));

View file

@ -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;
}

View file

@ -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.

View file

@ -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;
}

View file

@ -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<length-1; i++) {
item = up_history_item_new ();
ret = up_history_item_set_from_string (item, parts[i]);