trivial: C99ify more for-loops

This commit is contained in:
Richard Hughes 2017-09-16 18:47:54 +01:00
parent 7965721015
commit 9e79223ecf
24 changed files with 182 additions and 316 deletions

View File

@ -216,11 +216,10 @@ gboolean
fwupd_device_has_guid (FwupdDevice *device, const gchar *guid) fwupd_device_has_guid (FwupdDevice *device, const gchar *guid)
{ {
FwupdDevicePrivate *priv = GET_PRIVATE (device); FwupdDevicePrivate *priv = GET_PRIVATE (device);
guint i;
g_return_val_if_fail (FWUPD_IS_DEVICE (device), FALSE); g_return_val_if_fail (FWUPD_IS_DEVICE (device), FALSE);
for (i = 0; i < priv->guids->len; i++) { for (guint i = 0; i < priv->guids->len; i++) {
const gchar *guid_tmp = g_ptr_array_index (priv->guids, i); const gchar *guid_tmp = g_ptr_array_index (priv->guids, i);
if (g_strcmp0 (guid, guid_tmp) == 0) if (g_strcmp0 (guid, guid_tmp) == 0)
return TRUE; return TRUE;
@ -1016,10 +1015,9 @@ fwupd_device_from_key_value (FwupdDevice *device, const gchar *key, GVariant *va
return; return;
} }
if (g_strcmp0 (key, FWUPD_RESULT_KEY_CHECKSUM) == 0) { if (g_strcmp0 (key, FWUPD_RESULT_KEY_CHECKSUM) == 0) {
guint i;
const gchar *checksums = g_variant_get_string (value, NULL); const gchar *checksums = g_variant_get_string (value, NULL);
g_auto(GStrv) split = g_strsplit (checksums, ",", -1); g_auto(GStrv) split = g_strsplit (checksums, ",", -1);
for (i = 0; split[i] != NULL; i++) for (guint i = 0; split[i] != NULL; i++)
fwupd_device_add_checksum (device, split[i]); fwupd_device_add_checksum (device, split[i]);
return; return;
} }
@ -1083,11 +1081,8 @@ fwupd_pad_kv_unx (GString *str, const gchar *key, guint64 value)
static void static void
fwupd_pad_kv_dfl (GString *str, const gchar *key, guint64 device_flags) fwupd_pad_kv_dfl (GString *str, const gchar *key, guint64 device_flags)
{ {
guint i; g_autoptr(GString) tmp = g_string_new ("");
g_autoptr(GString) tmp = NULL; for (guint i = 0; i < 64; i++) {
tmp = g_string_new ("");
for (i = 0; i < 64; i++) {
if ((device_flags & ((guint64) 1 << i)) == 0) if ((device_flags & ((guint64) 1 << i)) == 0)
continue; continue;
g_string_append_printf (tmp, "%s|", g_string_append_printf (tmp, "%s|",

View File

@ -622,9 +622,8 @@ fwupd_release_to_data (FwupdRelease *release, const gchar *type_string)
g_variant_new_string (priv->description)); g_variant_new_string (priv->description));
} }
if (priv->checksums->len > 0) { if (priv->checksums->len > 0) {
guint i;
g_autoptr(GString) str = g_string_new (""); g_autoptr(GString) str = g_string_new ("");
for (i = 0; i < priv->checksums->len; i++) { for (guint i = 0; i < priv->checksums->len; i++) {
const gchar *checksum = g_ptr_array_index (priv->checksums, i); const gchar *checksum = g_ptr_array_index (priv->checksums, i);
g_string_append_printf (str, "%s,", checksum); g_string_append_printf (str, "%s,", checksum);
} }
@ -759,11 +758,8 @@ fwupd_pad_kv_siz (GString *str, const gchar *key, guint64 value)
static void static void
fwupd_pad_kv_tfl (GString *str, const gchar *key, FwupdTrustFlags trust_flags) fwupd_pad_kv_tfl (GString *str, const gchar *key, FwupdTrustFlags trust_flags)
{ {
guint i; g_autoptr(GString) tmp = g_string_new ("");
g_autoptr(GString) tmp = NULL; for (guint i = 1; i < FWUPD_TRUST_FLAG_LAST; i *= 2) {
tmp = g_string_new ("");
for (i = 1; i < FWUPD_TRUST_FLAG_LAST; i *= 2) {
if ((trust_flags & i) == 0) if ((trust_flags & i) == 0)
continue; continue;
g_string_append_printf (tmp, "%s|", g_string_append_printf (tmp, "%s|",

View File

@ -59,34 +59,31 @@ as_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
static void static void
fwupd_enums_func (void) fwupd_enums_func (void)
{ {
const gchar *tmp;
guint64 i;
/* enums */ /* enums */
for (i = 0; i < FWUPD_ERROR_LAST; i++) { for (guint i = 0; i < FWUPD_ERROR_LAST; i++) {
tmp = fwupd_error_to_string (i); const gchar *tmp = fwupd_error_to_string (i);
g_assert_cmpstr (tmp, !=, NULL); g_assert_cmpstr (tmp, !=, NULL);
g_assert_cmpint (fwupd_error_from_string (tmp), ==, i); g_assert_cmpint (fwupd_error_from_string (tmp), ==, i);
} }
for (i = 0; i < FWUPD_STATUS_LAST; i++) { for (guint i = 0; i < FWUPD_STATUS_LAST; i++) {
tmp = fwupd_status_to_string (i); const gchar *tmp = fwupd_status_to_string (i);
g_assert_cmpstr (tmp, !=, NULL); g_assert_cmpstr (tmp, !=, NULL);
g_assert_cmpint (fwupd_status_from_string (tmp), ==, i); g_assert_cmpint (fwupd_status_from_string (tmp), ==, i);
} }
for (i = 0; i < FWUPD_UPDATE_STATE_LAST; i++) { for (guint i = 0; i < FWUPD_UPDATE_STATE_LAST; i++) {
tmp = fwupd_update_state_to_string (i); const gchar *tmp = fwupd_update_state_to_string (i);
g_assert_cmpstr (tmp, !=, NULL); g_assert_cmpstr (tmp, !=, NULL);
g_assert_cmpint (fwupd_update_state_from_string (tmp), ==, i); g_assert_cmpint (fwupd_update_state_from_string (tmp), ==, i);
} }
for (i = 0; i < FWUPD_TRUST_FLAG_LAST; i++) { for (guint i = 0; i < FWUPD_TRUST_FLAG_LAST; i++) {
tmp = fwupd_trust_flag_to_string (i); const gchar *tmp = fwupd_trust_flag_to_string (i);
g_assert_cmpstr (tmp, !=, NULL); g_assert_cmpstr (tmp, !=, NULL);
g_assert_cmpint (fwupd_trust_flag_from_string (tmp), ==, i); g_assert_cmpint (fwupd_trust_flag_from_string (tmp), ==, i);
} }
/* bitfield */ /* bitfield */
for (i = 1; i < FWUPD_DEVICE_FLAG_UNKNOWN; i *= 2) { for (guint64 i = 1; i < FWUPD_DEVICE_FLAG_UNKNOWN; i *= 2) {
tmp = fwupd_device_flag_to_string (i); const gchar *tmp = fwupd_device_flag_to_string (i);
if (tmp == NULL) if (tmp == NULL)
break; break;
g_assert_cmpint (fwupd_device_flag_from_string (tmp), ==, i); g_assert_cmpint (fwupd_device_flag_from_string (tmp), ==, i);

View File

@ -36,9 +36,7 @@ fu_altos_tool_write_progress_cb (goffset current, goffset total, gpointer user_d
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
gsize len; gsize len;
guint i;
g_autofree guint8 *data = NULL; g_autofree guint8 *data = NULL;
g_autoptr(FuDeviceAltos) dev = NULL; g_autoptr(FuDeviceAltos) dev = NULL;
g_autoptr(GBytes) fw = NULL; g_autoptr(GBytes) fw = NULL;
@ -62,7 +60,7 @@ main (int argc, char **argv)
} }
g_usb_context_enumerate (usb_ctx); g_usb_context_enumerate (usb_ctx);
devices = g_usb_context_get_devices (usb_ctx); devices = g_usb_context_get_devices (usb_ctx);
for (i = 0; i < devices->len; i++) { for (guint i = 0; i < devices->len; i++) {
GUsbDevice *usb_dev_tmp = g_ptr_array_index (devices, i); GUsbDevice *usb_dev_tmp = g_ptr_array_index (devices, i);
g_autoptr(FuDeviceAltos) dev_tmp = fu_device_altos_new (usb_dev_tmp); g_autoptr(FuDeviceAltos) dev_tmp = fu_device_altos_new (usb_dev_tmp);
if (dev_tmp == NULL) if (dev_tmp == NULL)

View File

@ -53,7 +53,6 @@ dfu_cipher_uint32_to_buf (guint8 *buf, guint buflen, const guint32 *array)
static gboolean static gboolean
dfu_tool_parse_xtea_key (const gchar *key, guint32 *keys, GError **error) dfu_tool_parse_xtea_key (const gchar *key, guint32 *keys, GError **error)
{ {
guint i;
gsize key_len; gsize key_len;
/* too long */ /* too long */
@ -69,7 +68,7 @@ dfu_tool_parse_xtea_key (const gchar *key, guint32 *keys, GError **error)
/* parse 4x32b values or generate a hash */ /* parse 4x32b values or generate a hash */
if (key_len == 32) { if (key_len == 32) {
for (i = 0; i < 4; i++) { for (guint8 i = 0; i < 4; i++) {
gchar buf[] = "xxxxxxxx"; gchar buf[] = "xxxxxxxx";
gchar *endptr; gchar *endptr;
guint64 tmp; guint64 tmp;
@ -123,8 +122,6 @@ dfu_cipher_decrypt_xtea (const gchar *key,
guint32 sum; guint32 sum;
guint32 v0; guint32 v0;
guint32 v1; guint32 v1;
guint8 i;
guint j;
guint32 chunks = length / 4; guint32 chunks = length / 4;
guint32 keys[4]; guint32 keys[4];
g_autofree guint32 *tmp = NULL; g_autofree guint32 *tmp = NULL;
@ -156,11 +153,11 @@ dfu_cipher_decrypt_xtea (const gchar *key,
dfu_cipher_buf_to_uint32 (data, length, tmp); dfu_cipher_buf_to_uint32 (data, length, tmp);
/* process buffer using XTEA keys */ /* process buffer using XTEA keys */
for (j = 0; j < chunks; j += 2) { for (guint j = 0; j < chunks; j += 2) {
v0 = tmp[j]; v0 = tmp[j];
v1 = tmp[j+1]; v1 = tmp[j+1];
sum = XTEA_DELTA * XTEA_NUM_ROUNDS; sum = XTEA_DELTA * XTEA_NUM_ROUNDS;
for (i = 0; i < XTEA_NUM_ROUNDS; i++) { for (guint8 i = 0; i < XTEA_NUM_ROUNDS; i++) {
v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + keys[(sum >> 11) & 3]); v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + keys[(sum >> 11) & 3]);
sum -= XTEA_DELTA; sum -= XTEA_DELTA;
v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + keys[sum & 3]); v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + keys[sum & 3]);
@ -194,8 +191,6 @@ dfu_cipher_encrypt_xtea (const gchar *key,
guint32 sum; guint32 sum;
guint32 v0; guint32 v0;
guint32 v1; guint32 v1;
guint8 i;
guint j;
guint32 chunks = length / 4; guint32 chunks = length / 4;
guint32 keys[4]; guint32 keys[4];
g_autofree guint32 *tmp = NULL; g_autofree guint32 *tmp = NULL;
@ -227,11 +222,11 @@ dfu_cipher_encrypt_xtea (const gchar *key,
dfu_cipher_buf_to_uint32 (data, length, tmp); dfu_cipher_buf_to_uint32 (data, length, tmp);
/* process buffer using XTEA keys */ /* process buffer using XTEA keys */
for (j = 0; j < chunks; j += 2) { for (guint j = 0; j < chunks; j += 2) {
sum = 0; sum = 0;
v0 = tmp[j]; v0 = tmp[j];
v1 = tmp[j+1]; v1 = tmp[j+1];
for (i = 0; i < XTEA_NUM_ROUNDS; i++) { for (guint8 i = 0; i < XTEA_NUM_ROUNDS; i++) {
v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + keys[sum & 3]); v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + keys[sum & 3]);
sum += XTEA_DELTA; sum += XTEA_DELTA;
v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + keys[(sum >> 11) & 3]); v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + keys[(sum >> 11) & 3]);

View File

@ -151,12 +151,10 @@ static DfuContextItem *
dfu_context_find_item_by_platform_id (DfuContext *context, const gchar *platform_id) dfu_context_find_item_by_platform_id (DfuContext *context, const gchar *platform_id)
{ {
DfuContextPrivate *priv = GET_PRIVATE (context); DfuContextPrivate *priv = GET_PRIVATE (context);
DfuContextItem *item;
guint i;
/* do we have this device */ /* do we have this device */
for (i = 0; i < priv->devices->len; i++) { for (guint i = 0; i < priv->devices->len; i++) {
item = g_ptr_array_index (priv->devices, i); DfuContextItem *item = g_ptr_array_index (priv->devices, i);
if (g_strcmp0 (dfu_device_get_platform_id (item->device), platform_id) == 0) if (g_strcmp0 (dfu_device_get_platform_id (item->device), platform_id) == 0)
return item; return item;
} }
@ -413,15 +411,13 @@ GPtrArray *
dfu_context_get_devices (DfuContext *context) dfu_context_get_devices (DfuContext *context)
{ {
DfuContextPrivate *priv = GET_PRIVATE (context); DfuContextPrivate *priv = GET_PRIVATE (context);
DfuContextItem *item;
GPtrArray *devices; GPtrArray *devices;
guint i;
g_return_val_if_fail (DFU_IS_CONTEXT (context), NULL); g_return_val_if_fail (DFU_IS_CONTEXT (context), NULL);
devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
for (i = 0; i < priv->devices->len; i++) { for (guint i = 0; i < priv->devices->len; i++) {
item = g_ptr_array_index (priv->devices, i); DfuContextItem *item = g_ptr_array_index (priv->devices, i);
g_ptr_array_add (devices, g_object_ref (item->device)); g_ptr_array_add (devices, g_object_ref (item->device));
} }
return devices; return devices;
@ -445,20 +441,17 @@ dfu_context_get_device_by_vid_pid (DfuContext *context,
GError **error) GError **error)
{ {
DfuContextPrivate *priv = GET_PRIVATE (context); DfuContextPrivate *priv = GET_PRIVATE (context);
DfuContextItem *item;
DfuDevice *device = NULL; DfuDevice *device = NULL;
GUsbDevice *dev;
guint i;
g_return_val_if_fail (DFU_IS_CONTEXT (context), NULL); g_return_val_if_fail (DFU_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* search all devices */ /* search all devices */
for (i = 0; i < priv->devices->len; i++) { for (guint i = 0; i < priv->devices->len; i++) {
/* match */ /* match */
item = g_ptr_array_index (priv->devices, i); DfuContextItem *item = g_ptr_array_index (priv->devices, i);
dev = dfu_device_get_usb_dev (item->device); GUsbDevice *dev = dfu_device_get_usb_dev (item->device);
if (g_usb_device_get_vid (dev) == vid && if (g_usb_device_get_vid (dev) == vid &&
g_usb_device_get_pid (dev) == pid) { g_usb_device_get_pid (dev) == pid) {
if (device != NULL) { if (device != NULL) {
@ -500,15 +493,13 @@ dfu_context_get_device_by_platform_id (DfuContext *context,
GError **error) GError **error)
{ {
DfuContextPrivate *priv = GET_PRIVATE (context); DfuContextPrivate *priv = GET_PRIVATE (context);
DfuContextItem *item;
guint i;
g_return_val_if_fail (DFU_IS_CONTEXT (context), NULL); g_return_val_if_fail (DFU_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* search all devices */ /* search all devices */
for (i = 0; i < priv->devices->len; i++) { for (guint i = 0; i < priv->devices->len; i++) {
item = g_ptr_array_index (priv->devices, i); DfuContextItem *item = g_ptr_array_index (priv->devices, i);
if (g_strcmp0 (dfu_device_get_platform_id (item->device), if (g_strcmp0 (dfu_device_get_platform_id (item->device),
platform_id) == 0) { platform_id) == 0) {
return g_object_ref (item->device); return g_object_ref (item->device);

View File

@ -373,8 +373,6 @@ static gboolean
dfu_device_add_targets (DfuDevice *device) dfu_device_add_targets (DfuDevice *device)
{ {
DfuDevicePrivate *priv = GET_PRIVATE (device); DfuDevicePrivate *priv = GET_PRIVATE (device);
guint i;
GUsbInterface *iface;
g_autoptr(GPtrArray) ifaces = NULL; g_autoptr(GPtrArray) ifaces = NULL;
/* add all DFU-capable targets */ /* add all DFU-capable targets */
@ -382,10 +380,10 @@ dfu_device_add_targets (DfuDevice *device)
if (ifaces == NULL) if (ifaces == NULL)
return FALSE; return FALSE;
g_ptr_array_set_size (priv->targets, 0); g_ptr_array_set_size (priv->targets, 0);
for (i = 0; i < ifaces->len; i++) { for (guint i = 0; i < ifaces->len; i++) {
GBytes *iface_data = NULL; GBytes *iface_data = NULL;
DfuTarget *target; DfuTarget *target;
iface = g_ptr_array_index (ifaces, i); GUsbInterface *iface = g_ptr_array_index (ifaces, i);
if (g_usb_interface_get_class (iface) != G_USB_DEVICE_CLASS_APPLICATION_SPECIFIC) if (g_usb_interface_get_class (iface) != G_USB_DEVICE_CLASS_APPLICATION_SPECIFIC)
continue; continue;
if (g_usb_interface_get_subclass (iface) != 0x01) if (g_usb_interface_get_subclass (iface) != 0x01)
@ -725,15 +723,13 @@ dfu_device_get_target_by_alt_setting (DfuDevice *device,
GError **error) GError **error)
{ {
DfuDevicePrivate *priv = GET_PRIVATE (device); DfuDevicePrivate *priv = GET_PRIVATE (device);
DfuTarget *target;
guint i;
g_return_val_if_fail (DFU_IS_DEVICE (device), NULL); g_return_val_if_fail (DFU_IS_DEVICE (device), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* find by ID */ /* find by ID */
for (i = 0; i < priv->targets->len; i++) { for (guint i = 0; i < priv->targets->len; i++) {
target = g_ptr_array_index (priv->targets, i); DfuTarget *target = g_ptr_array_index (priv->targets, i);
if (dfu_target_get_alt_setting (target) == alt_setting) if (dfu_target_get_alt_setting (target) == alt_setting)
return g_object_ref (target); return g_object_ref (target);
} }
@ -763,15 +759,13 @@ dfu_device_get_target_by_alt_name (DfuDevice *device,
GError **error) GError **error)
{ {
DfuDevicePrivate *priv = GET_PRIVATE (device); DfuDevicePrivate *priv = GET_PRIVATE (device);
DfuTarget *target;
guint i;
g_return_val_if_fail (DFU_IS_DEVICE (device), NULL); g_return_val_if_fail (DFU_IS_DEVICE (device), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* find by ID */ /* find by ID */
for (i = 0; i < priv->targets->len; i++) { for (guint i = 0; i < priv->targets->len; i++) {
target = g_ptr_array_index (priv->targets, i); DfuTarget *target = g_ptr_array_index (priv->targets, i);
if (g_strcmp0 (dfu_target_get_alt_name (target, NULL), alt_name) == 0) if (g_strcmp0 (dfu_target_get_alt_name (target, NULL), alt_name) == 0)
return g_object_ref (target); return g_object_ref (target);
} }
@ -1747,7 +1741,6 @@ dfu_device_upload (DfuDevice *device,
GError **error) GError **error)
{ {
DfuDevicePrivate *priv = GET_PRIVATE (device); DfuDevicePrivate *priv = GET_PRIVATE (device);
guint i;
g_autoptr(DfuFirmware) firmware = NULL; g_autoptr(DfuFirmware) firmware = NULL;
/* no backing USB device */ /* no backing USB device */
@ -1792,7 +1785,7 @@ dfu_device_upload (DfuDevice *device,
} }
/* upload from each target */ /* upload from each target */
for (i = 0; i < priv->targets->len; i++) { for (guint i = 0; i < priv->targets->len; i++) {
DfuTarget *target; DfuTarget *target;
const gchar *alt_name; const gchar *alt_name;
gulong id1; gulong id1;
@ -1899,7 +1892,6 @@ dfu_device_download (DfuDevice *device,
DfuDevicePrivate *priv = GET_PRIVATE (device); DfuDevicePrivate *priv = GET_PRIVATE (device);
GPtrArray *images; GPtrArray *images;
gboolean ret; gboolean ret;
guint i;
/* no backing USB device */ /* no backing USB device */
if (priv->dev == NULL) { if (priv->dev == NULL) {
@ -1999,7 +1991,7 @@ dfu_device_download (DfuDevice *device,
"no images in firmware file"); "no images in firmware file");
return FALSE; return FALSE;
} }
for (i = 0; i < images->len; i++) { for (guint i = 0; i < images->len; i++) {
DfuCipherKind cipher_fw; DfuCipherKind cipher_fw;
DfuCipherKind cipher_target; DfuCipherKind cipher_target;
DfuImage *image; DfuImage *image;

View File

@ -120,14 +120,12 @@ DfuImage *
dfu_firmware_get_image (DfuFirmware *firmware, guint8 alt_setting) dfu_firmware_get_image (DfuFirmware *firmware, guint8 alt_setting)
{ {
DfuFirmwarePrivate *priv = GET_PRIVATE (firmware); DfuFirmwarePrivate *priv = GET_PRIVATE (firmware);
DfuImage *im;
guint i;
g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), NULL); g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), NULL);
/* find correct image */ /* find correct image */
for (i = 0; i < priv->images->len; i++) { for (guint i = 0; i < priv->images->len; i++) {
im = g_ptr_array_index (priv->images, i); DfuImage *im = g_ptr_array_index (priv->images, i);
if (dfu_image_get_alt_setting (im) == alt_setting) if (dfu_image_get_alt_setting (im) == alt_setting)
return im; return im;
} }
@ -147,14 +145,12 @@ DfuImage *
dfu_firmware_get_image_by_name (DfuFirmware *firmware, const gchar *name) dfu_firmware_get_image_by_name (DfuFirmware *firmware, const gchar *name)
{ {
DfuFirmwarePrivate *priv = GET_PRIVATE (firmware); DfuFirmwarePrivate *priv = GET_PRIVATE (firmware);
DfuImage *im;
guint i;
g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), NULL); g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), NULL);
/* find correct image */ /* find correct image */
for (i = 0; i < priv->images->len; i++) { for (guint i = 0; i < priv->images->len; i++) {
im = g_ptr_array_index (priv->images, i); DfuImage *im = g_ptr_array_index (priv->images, i);
if (g_strcmp0 (dfu_image_get_name (im), name) == 0) if (g_strcmp0 (dfu_image_get_name (im), name) == 0)
return im; return im;
} }
@ -211,9 +207,8 @@ dfu_firmware_get_size (DfuFirmware *firmware)
{ {
DfuFirmwarePrivate *priv = GET_PRIVATE (firmware); DfuFirmwarePrivate *priv = GET_PRIVATE (firmware);
guint32 length = 0; guint32 length = 0;
guint i;
g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), 0); g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), 0);
for (i = 0; i < priv->images->len; i++) { for (guint i = 0; i < priv->images->len; i++) {
DfuImage *image = g_ptr_array_index (priv->images, i); DfuImage *image = g_ptr_array_index (priv->images, i);
length += dfu_image_get_size (image); length += dfu_image_get_size (image);
} }
@ -649,9 +644,7 @@ dfu_firmware_to_string (DfuFirmware *firmware)
{ {
DfuFirmwarePrivate *priv = GET_PRIVATE (firmware); DfuFirmwarePrivate *priv = GET_PRIVATE (firmware);
DfuImage *image; DfuImage *image;
GList *l;
GString *str; GString *str;
guint i;
g_autofree gchar *release_str = NULL; g_autofree gchar *release_str = NULL;
g_autoptr(GList) keys = NULL; g_autoptr(GList) keys = NULL;
@ -672,16 +665,15 @@ dfu_firmware_to_string (DfuFirmware *firmware)
/* print metadata */ /* print metadata */
keys = g_hash_table_get_keys (priv->metadata); keys = g_hash_table_get_keys (priv->metadata);
for (l = keys; l != NULL; l = l->next) { for (GList *l = keys; l != NULL; l = l->next) {
const gchar *key; const gchar *key = l->data;
const gchar *value; const gchar *value;
key = l->data;
value = g_hash_table_lookup (priv->metadata, key); value = g_hash_table_lookup (priv->metadata, key);
g_string_append_printf (str, "metadata: %s=%s\n", key, value); g_string_append_printf (str, "metadata: %s=%s\n", key, value);
} }
/* print images */ /* print images */
for (i = 0; i < priv->images->len; i++) { for (guint i = 0; i < priv->images->len; i++) {
g_autofree gchar *tmp = NULL; g_autofree gchar *tmp = NULL;
image = g_ptr_array_index (priv->images, i); image = g_ptr_array_index (priv->images, i);
tmp = dfu_image_to_string (image); tmp = dfu_image_to_string (image);

View File

@ -128,9 +128,8 @@ static guint32 _crctbl[] = {
static guint32 static guint32
dfu_firmware_generate_crc32 (const guint8 *data, gsize length) dfu_firmware_generate_crc32 (const guint8 *data, gsize length)
{ {
guint i;
guint32 accum = 0xffffffff; guint32 accum = 0xffffffff;
for (i = 0; i < length; i++) for (guint i = 0; i < length; i++)
accum = _crctbl[(accum^data[i]) & 0xff] ^ (accum >> 8); accum = _crctbl[(accum^data[i]) & 0xff] ^ (accum >> 8);
return accum; return accum;
} }

View File

@ -150,7 +150,6 @@ dfu_image_from_dfuse (const guint8 *data,
DfuSeImagePrefix *im; DfuSeImagePrefix *im;
guint32 elements; guint32 elements;
guint32 offset = sizeof(DfuSeImagePrefix); guint32 offset = sizeof(DfuSeImagePrefix);
guint j;
g_autoptr(DfuImage) image = NULL; g_autoptr(DfuImage) image = NULL;
g_assert_cmpint(sizeof(DfuSeImagePrefix), ==, 274); g_assert_cmpint(sizeof(DfuSeImagePrefix), ==, 274);
@ -184,7 +183,7 @@ dfu_image_from_dfuse (const guint8 *data,
/* parse elements */ /* parse elements */
length -= offset; length -= offset;
elements = GUINT32_FROM_LE (im->elements); elements = GUINT32_FROM_LE (im->elements);
for (j = 0; j < elements; j++) { for (guint j = 0; j < elements; j++) {
guint32 consumed_local; guint32 consumed_local;
g_autoptr(DfuElement) element = NULL; g_autoptr(DfuElement) element = NULL;
element = dfu_element_from_dfuse (data + offset, length, element = dfu_element_from_dfuse (data + offset, length,
@ -214,22 +213,19 @@ dfu_image_from_dfuse (const guint8 *data,
static GBytes * static GBytes *
dfu_image_to_dfuse (DfuImage *image) dfu_image_to_dfuse (DfuImage *image)
{ {
DfuElement *element;
DfuSeImagePrefix *im; DfuSeImagePrefix *im;
GBytes *bytes;
GPtrArray *elements; GPtrArray *elements;
guint32 length_total = 0; guint32 length_total = 0;
guint32 offset = sizeof (DfuSeImagePrefix); guint32 offset = sizeof (DfuSeImagePrefix);
guint8 *buf; guint8 *buf;
guint i;
g_autoptr(GPtrArray) element_array = NULL; g_autoptr(GPtrArray) element_array = NULL;
/* get total size */ /* get total size */
element_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); element_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
elements = dfu_image_get_elements (image); elements = dfu_image_get_elements (image);
for (i = 0; i < elements->len; i++) { for (guint i = 0; i < elements->len; i++) {
element = g_ptr_array_index (elements, i); DfuElement *element = g_ptr_array_index (elements, i);
bytes = dfu_element_to_dfuse (element); GBytes *bytes = dfu_element_to_dfuse (element);
g_ptr_array_add (element_array, bytes); g_ptr_array_add (element_array, bytes);
length_total += (guint32) g_bytes_get_size (bytes); length_total += (guint32) g_bytes_get_size (bytes);
} }
@ -247,11 +243,10 @@ dfu_image_to_dfuse (DfuImage *image)
im->elements = GUINT32_TO_LE (elements->len); im->elements = GUINT32_TO_LE (elements->len);
/* copy data */ /* copy data */
for (i = 0; i < element_array->len; i++) { for (guint i = 0; i < element_array->len; i++) {
const guint8 *data;
gsize length; gsize length;
bytes = g_ptr_array_index (element_array, i); GBytes *bytes = g_ptr_array_index (element_array, i);
data = g_bytes_get_data (bytes, &length); const guint8 *data = g_bytes_get_data (bytes, &length);
memcpy (buf + offset, data, length); memcpy (buf + offset, data, length);
offset += (guint32) length; offset += (guint32) length;
} }
@ -280,7 +275,6 @@ dfu_firmware_to_dfuse (DfuFirmware *firmware, GError **error)
{ {
DfuSePrefix *prefix; DfuSePrefix *prefix;
GPtrArray *images; GPtrArray *images;
guint i;
guint32 image_size_total = 0; guint32 image_size_total = 0;
guint32 offset = sizeof (DfuSePrefix); guint32 offset = sizeof (DfuSePrefix);
g_autofree guint8 *buf = NULL; g_autofree guint8 *buf = NULL;
@ -289,7 +283,7 @@ dfu_firmware_to_dfuse (DfuFirmware *firmware, GError **error)
/* get all the image data */ /* get all the image data */
dfuse_images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); dfuse_images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
images = dfu_firmware_get_images (firmware); images = dfu_firmware_get_images (firmware);
for (i = 0; i < images->len; i++) { for (guint i = 0; i < images->len; i++) {
DfuImage *im = g_ptr_array_index (images, i); DfuImage *im = g_ptr_array_index (images, i);
GBytes *contents; GBytes *contents;
contents = dfu_image_to_dfuse (im); contents = dfu_image_to_dfuse (im);
@ -316,7 +310,7 @@ dfu_firmware_to_dfuse (DfuFirmware *firmware, GError **error)
prefix->targets = (guint8) images->len; prefix->targets = (guint8) images->len;
/* copy images */ /* copy images */
for (i = 0; i < dfuse_images->len; i++) { for (guint i = 0; i < dfuse_images->len; i++) {
GBytes *contents = g_ptr_array_index (dfuse_images, i); GBytes *contents = g_ptr_array_index (dfuse_images, i);
gsize length; gsize length;
const guint8 *data; const guint8 *data;
@ -350,7 +344,6 @@ dfu_firmware_from_dfuse (DfuFirmware *firmware,
gsize len; gsize len;
guint32 offset = sizeof(DfuSePrefix); guint32 offset = sizeof(DfuSePrefix);
guint8 *data; guint8 *data;
guint i;
/* check the prefix (BE) */ /* check the prefix (BE) */
data = (guint8 *) g_bytes_get_data (bytes, &len); data = (guint8 *) g_bytes_get_data (bytes, &len);
@ -388,7 +381,7 @@ dfu_firmware_from_dfuse (DfuFirmware *firmware,
/* parse the image targets */ /* parse the image targets */
len -= sizeof(DfuSePrefix); len -= sizeof(DfuSePrefix);
for (i = 0; i < prefix->targets; i++) { for (guint i = 0; i < prefix->targets; i++) {
guint consumed; guint consumed;
g_autoptr(DfuImage) image = NULL; g_autoptr(DfuImage) image = NULL;
image = dfu_image_from_dfuse (data + offset, (guint32) len, image = dfu_image_from_dfuse (data + offset, (guint32) len,

View File

@ -104,8 +104,6 @@ dfu_firmware_from_ihex (DfuFirmware *firmware,
guint8 len_tmp; guint8 len_tmp;
guint8 type; guint8 type;
guint end; guint end;
guint i;
guint j;
guint offset = 0; guint offset = 0;
g_autoptr(DfuElement) element = NULL; g_autoptr(DfuElement) element = NULL;
g_autoptr(DfuImage) image = NULL; g_autoptr(DfuImage) image = NULL;
@ -164,7 +162,7 @@ dfu_firmware_from_ihex (DfuFirmware *firmware,
/* verify checksum */ /* verify checksum */
if ((flags & DFU_FIRMWARE_PARSE_FLAG_NO_CRC_TEST) == 0) { if ((flags & DFU_FIRMWARE_PARSE_FLAG_NO_CRC_TEST) == 0) {
checksum = 0; checksum = 0;
for (i = offset + 1; i < end + 2; i += 2) { for (guint i = offset + 1; i < end + 2; i += 2) {
data_tmp = dfu_firmware_ihex_parse_uint8 (in_buffer, i); data_tmp = dfu_firmware_ihex_parse_uint8 (in_buffer, i);
checksum += data_tmp; checksum += data_tmp;
} }
@ -204,11 +202,11 @@ dfu_firmware_from_ihex (DfuFirmware *firmware,
/* parse bytes from line */ /* parse bytes from line */
g_debug ("writing data 0x%08x", (guint32) addr32); g_debug ("writing data 0x%08x", (guint32) addr32);
for (i = offset + 9; i < end; i += 2) { for (guint i = offset + 9; i < end; i += 2) {
/* any holes in the hex record */ /* any holes in the hex record */
guint32 len_hole = addr32 - addr32_last; guint32 len_hole = addr32 - addr32_last;
if (addr32_last > 0x0 && len_hole > 1) { if (addr32_last > 0x0 && len_hole > 1) {
for (j = 1; j < len_hole; j++) { for (guint j = 1; j < len_hole; j++) {
g_debug ("filling address 0x%08x", g_debug ("filling address 0x%08x",
addr32_last + j); addr32_last + j);
/* although 0xff might be clearer, /* although 0xff might be clearer,
@ -238,7 +236,7 @@ dfu_firmware_from_ihex (DfuFirmware *firmware,
addr32 = ((guint32) addr_high << 16) + addr_low; addr32 = ((guint32) addr_high << 16) + addr_low;
break; break;
case DFU_INHX32_RECORD_TYPE_SIGNATURE: case DFU_INHX32_RECORD_TYPE_SIGNATURE:
for (i = offset + 9; i < end; i += 2) { for (guint i = offset + 9; i < end; i += 2) {
guint8 tmp_c = dfu_firmware_ihex_parse_uint8 (in_buffer, i); guint8 tmp_c = dfu_firmware_ihex_parse_uint8 (in_buffer, i);
g_string_append_c (signature, tmp_c); g_string_append_c (signature, tmp_c);
} }

View File

@ -59,7 +59,6 @@ dfu_firmware_from_metadata (DfuFirmware *firmware,
{ {
const guint8 *data; const guint8 *data;
gsize data_length; gsize data_length;
guint i;
guint idx = 2; guint idx = 2;
guint kvlen; guint kvlen;
guint number_keys; guint number_keys;
@ -75,7 +74,7 @@ dfu_firmware_from_metadata (DfuFirmware *firmware,
/* parse key=value store */ /* parse key=value store */
number_keys = data[idx++]; number_keys = data[idx++];
for (i = 0; i < number_keys; i++) { for (guint i = 0; i < number_keys; i++) {
g_autofree gchar *key = NULL; g_autofree gchar *key = NULL;
g_autofree gchar *value = NULL; g_autofree gchar *value = NULL;
@ -137,7 +136,6 @@ dfu_firmware_from_metadata (DfuFirmware *firmware,
GBytes * GBytes *
dfu_firmware_to_metadata (DfuFirmware *firmware, GError **error) dfu_firmware_to_metadata (DfuFirmware *firmware, GError **error)
{ {
GList *l;
GHashTable *metadata; GHashTable *metadata;
guint8 mdbuf[239]; guint8 mdbuf[239];
guint idx = 0; guint idx = 0;
@ -165,7 +163,7 @@ dfu_firmware_to_metadata (DfuFirmware *firmware, GError **error)
mdbuf[idx++] = 'M'; mdbuf[idx++] = 'M';
mdbuf[idx++] = 'D'; mdbuf[idx++] = 'D';
mdbuf[idx++] = (guint8) number_keys; mdbuf[idx++] = (guint8) number_keys;
for (l = keys; l != NULL; l = l->next) { for (GList *l = keys; l != NULL; l = l->next) {
const gchar *key; const gchar *key;
const gchar *value; const gchar *value;
guint key_len; guint key_len;

View File

@ -191,9 +191,8 @@ dfu_image_get_size (DfuImage *image)
{ {
DfuImagePrivate *priv = GET_PRIVATE (image); DfuImagePrivate *priv = GET_PRIVATE (image);
guint32 length = 0; guint32 length = 0;
guint i;
g_return_val_if_fail (DFU_IS_IMAGE (image), 0); g_return_val_if_fail (DFU_IS_IMAGE (image), 0);
for (i = 0; i < priv->elements->len; i++) { for (guint i = 0; i < priv->elements->len; i++) {
DfuElement *element = g_ptr_array_index (priv->elements, i); DfuElement *element = g_ptr_array_index (priv->elements, i);
length += (guint32) g_bytes_get_size (dfu_element_get_contents (element)); length += (guint32) g_bytes_get_size (dfu_element_get_contents (element));
} }
@ -270,7 +269,6 @@ dfu_image_to_string (DfuImage *image)
{ {
DfuImagePrivate *priv = GET_PRIVATE (image); DfuImagePrivate *priv = GET_PRIVATE (image);
GString *str; GString *str;
guint i;
g_return_val_if_fail (DFU_IS_IMAGE (image), NULL); g_return_val_if_fail (DFU_IS_IMAGE (image), NULL);
@ -282,7 +280,7 @@ dfu_image_to_string (DfuImage *image)
priv->elements->len); priv->elements->len);
/* add elements */ /* add elements */
for (i = 0; i < priv->elements->len; i++) { for (guint i = 0; i < priv->elements->len; i++) {
DfuElement *element = g_ptr_array_index (priv->elements, i); DfuElement *element = g_ptr_array_index (priv->elements, i);
g_autofree gchar *tmp = NULL; g_autofree gchar *tmp = NULL;
tmp = dfu_element_to_string (element); tmp = dfu_element_to_string (element);

View File

@ -83,7 +83,6 @@ static gboolean
dfu_progress_bar_draw (DfuProgressBar *self, gint percentage) dfu_progress_bar_draw (DfuProgressBar *self, gint percentage)
{ {
guint section; guint section;
guint i;
GString *str; GString *str;
/* no value yet */ /* no value yet */
@ -96,9 +95,9 @@ dfu_progress_bar_draw (DfuProgressBar *self, gint percentage)
section = (guint) ((gfloat) self->size / (gfloat) 100.0 * (gfloat) percentage); section = (guint) ((gfloat) self->size / (gfloat) 100.0 * (gfloat) percentage);
g_string_append (str, "["); g_string_append (str, "[");
for (i = 0; i < section; i++) for (guint i = 0; i < section; i++)
g_string_append (str, "="); g_string_append (str, "=");
for (i = 0; i < self->size - section; i++) for (guint i = 0; i < self->size - section; i++)
g_string_append (str, " "); g_string_append (str, " ");
g_string_append (str, "] "); g_string_append (str, "] ");
if (percentage >= 0 && percentage < 100) if (percentage >= 0 && percentage < 100)

View File

@ -84,7 +84,6 @@ _g_bytes_compare_verbose (GBytes *bytes1, GBytes *bytes2)
const guint8 *data2; const guint8 *data2;
gsize length1; gsize length1;
gsize length2; gsize length2;
guint i;
data1 = g_bytes_get_data (bytes1, &length1); data1 = g_bytes_get_data (bytes1, &length1);
data2 = g_bytes_get_data (bytes2, &length2); data2 = g_bytes_get_data (bytes2, &length2);
@ -97,7 +96,7 @@ _g_bytes_compare_verbose (GBytes *bytes1, GBytes *bytes2)
} }
/* return 00 01 02 03 */ /* return 00 01 02 03 */
for (i = 0; i < length1; i++) { for (guint i = 0; i < length1; i++) {
if (data1[i] != data2[i]) { if (data1[i] != data2[i]) {
return g_strdup_printf ("got 0x%02x, expected 0x%02x @ 0x%04x", return g_strdup_printf ("got 0x%02x, expected 0x%02x @ 0x%04x",
data1[i], data2[i], i); data1[i], data2[i], i);
@ -164,10 +163,9 @@ dfu_firmware_xdfu_func (void)
static void static void
dfu_enums_func (void) dfu_enums_func (void)
{ {
guint i; for (guint i = 0; i < DFU_STATE_LAST; i++)
for (i = 0; i < DFU_STATE_LAST; i++)
g_assert_cmpstr (dfu_state_to_string (i), !=, NULL); g_assert_cmpstr (dfu_state_to_string (i), !=, NULL);
for (i = 0; i < DFU_STATUS_LAST; i++) for (guint i = 0; i < DFU_STATUS_LAST; i++)
g_assert_cmpstr (dfu_status_to_string (i), !=, NULL); g_assert_cmpstr (dfu_status_to_string (i), !=, NULL);
} }
@ -188,7 +186,6 @@ dfu_firmware_raw_func (void)
DfuImage *image_tmp; DfuImage *image_tmp;
GBytes *no_suffix_contents; GBytes *no_suffix_contents;
gchar buf[256]; gchar buf[256];
guint i;
gboolean ret; gboolean ret;
g_autoptr(DfuFirmware) firmware = NULL; g_autoptr(DfuFirmware) firmware = NULL;
g_autoptr(GBytes) fw = NULL; g_autoptr(GBytes) fw = NULL;
@ -196,7 +193,7 @@ dfu_firmware_raw_func (void)
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
/* set up some dummy data */ /* set up some dummy data */
for (i = 0; i < 256; i++) for (guint i = 0; i < 256; i++)
buf[i] = (gchar) i; buf[i] = (gchar) i;
fw = g_bytes_new_static (buf, 256); fw = g_bytes_new_static (buf, 256);
@ -232,7 +229,6 @@ static void
dfu_firmware_dfu_func (void) dfu_firmware_dfu_func (void)
{ {
gchar buf[256]; gchar buf[256];
guint i;
gboolean ret; gboolean ret;
g_autofree gchar *filename = NULL; g_autofree gchar *filename = NULL;
g_autoptr(DfuFirmware) firmware = NULL; g_autoptr(DfuFirmware) firmware = NULL;
@ -246,7 +242,7 @@ dfu_firmware_dfu_func (void)
g_autoptr(GFile) file = NULL; g_autoptr(GFile) file = NULL;
/* set up some dummy data */ /* set up some dummy data */
for (i = 0; i < 256; i++) for (guint i = 0; i < 256; i++)
buf[i] = (gchar) i; buf[i] = (gchar) i;
fw = g_bytes_new_static (buf, 256); fw = g_bytes_new_static (buf, 256);
@ -674,17 +670,14 @@ dfu_colorhug_plus_func (void)
static gchar * static gchar *
dfu_target_sectors_to_string (DfuTarget *target) dfu_target_sectors_to_string (DfuTarget *target)
{ {
DfuSector *sector;
GPtrArray *sectors; GPtrArray *sectors;
GString *str; GString *str;
guint i;
str = g_string_new (""); str = g_string_new ("");
sectors = dfu_target_get_sectors (target); sectors = dfu_target_get_sectors (target);
for (i = 0; i < sectors->len; i++) { for (guint i = 0; i < sectors->len; i++) {
g_autofree gchar *tmp = NULL; DfuSector *sector = g_ptr_array_index (sectors, i);
sector = g_ptr_array_index (sectors, i); g_autofree gchar *tmp = dfu_sector_to_string (sector);
tmp = dfu_sector_to_string (sector);
g_string_append_printf (str, "%s\n", tmp); g_string_append_printf (str, "%s\n", tmp);
} }
if (str->len > 0) if (str->len > 0)

View File

@ -147,15 +147,10 @@ static gchar *
dfu_target_sectors_to_string (DfuTarget *target) dfu_target_sectors_to_string (DfuTarget *target)
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
DfuSector *sector; GString *str = g_string_new ("");
GString *str; for (guint i = 0; i < priv->sectors->len; i++) {
guint i; DfuSector *sector = g_ptr_array_index (priv->sectors, i);
g_autofree gchar *tmp = dfu_sector_to_string (sector);
str = g_string_new ("");
for (i = 0; i < priv->sectors->len; i++) {
g_autofree gchar *tmp = NULL;
sector = g_ptr_array_index (priv->sectors, i);
tmp = dfu_sector_to_string (sector);
g_string_append_printf (str, "%s\n", tmp); g_string_append_printf (str, "%s\n", tmp);
} }
if (str->len > 0) if (str->len > 0)
@ -167,11 +162,9 @@ static DfuSector *
dfu_target_get_sector_for_addr (DfuTarget *target, guint32 addr) dfu_target_get_sector_for_addr (DfuTarget *target, guint32 addr)
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
DfuSector *sector;
guint i;
for (i = 0; i < priv->sectors->len; i++) { for (guint i = 0; i < priv->sectors->len; i++) {
sector = g_ptr_array_index (priv->sectors, i); DfuSector *sector = g_ptr_array_index (priv->sectors, i);
if (addr < dfu_sector_get_address (sector)) if (addr < dfu_sector_get_address (sector))
continue; continue;
if (addr > dfu_sector_get_address (sector) + if (addr > dfu_sector_get_address (sector) +
@ -196,7 +189,6 @@ dfu_target_parse_sector (DfuTarget *target,
guint32 addr_offset = 0; guint32 addr_offset = 0;
guint64 nr_sectors; guint64 nr_sectors;
guint64 sector_size; guint64 sector_size;
guint i;
/* parse # of sectors */ /* parse # of sectors */
nr_sectors = g_ascii_strtoull (dfuse_sector_id, &tmp, 10); nr_sectors = g_ascii_strtoull (dfuse_sector_id, &tmp, 10);
@ -288,7 +280,7 @@ dfu_target_parse_sector (DfuTarget *target,
} }
/* add all the sectors */ /* add all the sectors */
for (i = 0; i < nr_sectors; i++) { for (guint i = 0; i < nr_sectors; i++) {
DfuSector *sector; DfuSector *sector;
sector = dfu_sector_new (*addr + addr_offset, sector = dfu_sector_new (*addr + addr_offset,
(guint32) sector_size, (guint32) sector_size,
@ -960,17 +952,16 @@ _g_bytes_array_join (GPtrArray *chunks)
gsize total_size = 0; gsize total_size = 0;
guint32 offset = 0; guint32 offset = 0;
guint8 *buffer; guint8 *buffer;
guint i;
/* get the size of all the chunks */ /* get the size of all the chunks */
for (i = 0; i < chunks->len; i++) { for (guint i = 0; i < chunks->len; i++) {
GBytes *chunk_tmp = g_ptr_array_index (chunks, i); GBytes *chunk_tmp = g_ptr_array_index (chunks, i);
total_size += g_bytes_get_size (chunk_tmp); total_size += g_bytes_get_size (chunk_tmp);
} }
/* copy them into a buffer */ /* copy them into a buffer */
buffer = g_malloc0 (total_size); buffer = g_malloc0 (total_size);
for (i = 0; i < chunks->len; i++) { for (guint i = 0; i < chunks->len; i++) {
const guint8 *chunk_data; const guint8 *chunk_data;
gsize chunk_size = 0; gsize chunk_size = 0;
GBytes *chunk_tmp = g_ptr_array_index (chunks, i); GBytes *chunk_tmp = g_ptr_array_index (chunks, i);
@ -999,7 +990,6 @@ dfu_target_upload_element_dfuse (DfuTarget *target,
guint percentage_size = expected_size > 0 ? expected_size : maximum_size; guint percentage_size = expected_size > 0 ? expected_size : maximum_size;
gsize total_size = 0; gsize total_size = 0;
guint16 transfer_size = dfu_device_get_transfer_size (priv->device); guint16 transfer_size = dfu_device_get_transfer_size (priv->device);
guint idx;
g_autoptr(GBytes) contents = NULL; g_autoptr(GBytes) contents = NULL;
g_autoptr(GBytes) contents_truncated = NULL; g_autoptr(GBytes) contents_truncated = NULL;
g_autoptr(GPtrArray) chunks = NULL; g_autoptr(GPtrArray) chunks = NULL;
@ -1043,7 +1033,7 @@ dfu_target_upload_element_dfuse (DfuTarget *target,
/* get all the chunks from the hardware */ /* get all the chunks from the hardware */
chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
for (idx = 0; idx < G_MAXUINT16; idx++) { for (guint idx = 0; idx < G_MAXUINT16; idx++) {
guint32 chunk_size; guint32 chunk_size;
/* read chunk of data -- ST uses wBlockNum=0 for DfuSe commands /* read chunk of data -- ST uses wBlockNum=0 for DfuSe commands
@ -1126,7 +1116,6 @@ dfu_target_upload_element_dfu (DfuTarget *target,
guint percentage_size = expected_size > 0 ? expected_size : maximum_size; guint percentage_size = expected_size > 0 ? expected_size : maximum_size;
gsize total_size = 0; gsize total_size = 0;
guint16 transfer_size = dfu_device_get_transfer_size (priv->device); guint16 transfer_size = dfu_device_get_transfer_size (priv->device);
guint idx;
g_autoptr(GBytes) contents = NULL; g_autoptr(GBytes) contents = NULL;
g_autoptr(GPtrArray) chunks = NULL; g_autoptr(GPtrArray) chunks = NULL;
@ -1135,7 +1124,7 @@ dfu_target_upload_element_dfu (DfuTarget *target,
/* get all the chunks from the hardware */ /* get all the chunks from the hardware */
chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
for (idx = 0; idx < G_MAXUINT16; idx++) { for (guint idx = 0; idx < G_MAXUINT16; idx++) {
guint32 chunk_size; guint32 chunk_size;
/* read chunk of data */ /* read chunk of data */
@ -1218,9 +1207,8 @@ static guint32
dfu_target_get_size_of_zone (DfuTarget *target, guint16 zone) dfu_target_get_size_of_zone (DfuTarget *target, guint16 zone)
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
guint i;
guint32 len = 0; guint32 len = 0;
for (i = 0; i < priv->sectors->len; i++) { for (guint i = 0; i < priv->sectors->len; i++) {
DfuSector *sector = g_ptr_array_index (priv->sectors, i); DfuSector *sector = g_ptr_array_index (priv->sectors, i);
if (dfu_sector_get_zone (sector) != zone) if (dfu_sector_get_zone (sector) != zone)
continue; continue;
@ -1248,7 +1236,6 @@ dfu_target_upload (DfuTarget *target,
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
DfuSector *sector; DfuSector *sector;
guint i;
guint16 zone_cur; guint16 zone_cur;
guint32 zone_size = 0; guint32 zone_size = 0;
guint32 zone_last = G_MAXUINT; guint32 zone_last = G_MAXUINT;
@ -1289,7 +1276,7 @@ dfu_target_upload (DfuTarget *target,
dfu_image_set_alt_setting (image, priv->alt_setting); dfu_image_set_alt_setting (image, priv->alt_setting);
/* get all the sectors for the device */ /* get all the sectors for the device */
for (i = 0; i < priv->sectors->len; i++) { for (guint i = 0; i < priv->sectors->len; i++) {
g_autoptr(DfuElement) element = NULL; g_autoptr(DfuElement) element = NULL;
/* only upload to the start of any zone:sector */ /* only upload to the start of any zone:sector */
@ -1347,7 +1334,6 @@ _g_bytes_compare_verbose (GBytes *bytes1, GBytes *bytes2)
const guint8 *data2; const guint8 *data2;
gsize length1; gsize length1;
gsize length2; gsize length2;
guint i;
data1 = g_bytes_get_data (bytes1, &length1); data1 = g_bytes_get_data (bytes1, &length1);
data2 = g_bytes_get_data (bytes2, &length2); data2 = g_bytes_get_data (bytes2, &length2);
@ -1360,7 +1346,7 @@ _g_bytes_compare_verbose (GBytes *bytes1, GBytes *bytes2)
} }
/* return 00 01 02 03 */ /* return 00 01 02 03 */
for (i = 0; i < length1; i++) { for (guint i = 0; i < length1; i++) {
if (data1[i] != data2[i]) { if (data1[i] != data2[i]) {
return g_strdup_printf ("got 0x%02x, expected 0x%02x @ 0x%04x", return g_strdup_printf ("got 0x%02x, expected 0x%02x @ 0x%04x",
data1[i], data2[i], i); data1[i], data2[i], i);
@ -1378,7 +1364,6 @@ dfu_target_download_element_dfu (DfuTarget *target,
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
GBytes *bytes; GBytes *bytes;
guint i;
guint nr_chunks; guint nr_chunks;
guint16 transfer_size = dfu_device_get_transfer_size (priv->device); guint16 transfer_size = dfu_device_get_transfer_size (priv->device);
@ -1394,7 +1379,7 @@ dfu_target_download_element_dfu (DfuTarget *target,
return FALSE; return FALSE;
} }
dfu_target_set_action (target, DFU_ACTION_WRITE); dfu_target_set_action (target, DFU_ACTION_WRITE);
for (i = 0; i < nr_chunks + 1; i++) { for (guint i = 0; i < nr_chunks + 1; i++) {
gsize length; gsize length;
guint32 offset; guint32 offset;
g_autoptr(GBytes) bytes_tmp = NULL; g_autoptr(GBytes) bytes_tmp = NULL;
@ -1442,7 +1427,6 @@ dfu_target_download_element_dfuse (DfuTarget *target,
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
DfuSector *sector; DfuSector *sector;
GBytes *bytes; GBytes *bytes;
guint i;
guint nr_chunks; guint nr_chunks;
guint zone_last = G_MAXUINT; guint zone_last = G_MAXUINT;
guint16 transfer_size = dfu_device_get_transfer_size (priv->device); guint16 transfer_size = dfu_device_get_transfer_size (priv->device);
@ -1464,7 +1448,7 @@ dfu_target_download_element_dfuse (DfuTarget *target,
/* 1st pass: work out which sectors need erasing */ /* 1st pass: work out which sectors need erasing */
sectors_array = g_ptr_array_new (); sectors_array = g_ptr_array_new ();
sectors_hash = g_hash_table_new (g_direct_hash, g_direct_equal); sectors_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
for (i = 0; i < nr_chunks; i++) { for (guint i = 0; i < nr_chunks; i++) {
guint32 offset_dev; guint32 offset_dev;
/* for DfuSe devices we need to handle the erase and setting /* for DfuSe devices we need to handle the erase and setting
@ -1503,7 +1487,7 @@ dfu_target_download_element_dfuse (DfuTarget *target,
/* 2nd pass: actually erase sectors */ /* 2nd pass: actually erase sectors */
dfu_target_set_action (target, DFU_ACTION_ERASE); dfu_target_set_action (target, DFU_ACTION_ERASE);
for (i = 0; i < sectors_array->len; i++) { for (guint i = 0; i < sectors_array->len; i++) {
sector = g_ptr_array_index (sectors_array, i); sector = g_ptr_array_index (sectors_array, i);
g_debug ("erasing sector at 0x%04x", g_debug ("erasing sector at 0x%04x",
dfu_sector_get_address (sector)); dfu_sector_get_address (sector));
@ -1519,7 +1503,7 @@ dfu_target_download_element_dfuse (DfuTarget *target,
/* 3rd pass: write data */ /* 3rd pass: write data */
dfu_target_set_action (target, DFU_ACTION_WRITE); dfu_target_set_action (target, DFU_ACTION_WRITE);
for (i = 0; i < nr_chunks; i++) { for (guint i = 0; i < nr_chunks; i++) {
gsize length; gsize length;
guint32 offset; guint32 offset;
guint32 offset_dev; guint32 offset_dev;
@ -1655,10 +1639,8 @@ dfu_target_download (DfuTarget *target, DfuImage *image,
GError **error) GError **error)
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
DfuElement *element;
GPtrArray *elements; GPtrArray *elements;
gboolean ret; gboolean ret;
guint i;
g_return_val_if_fail (DFU_IS_TARGET (target), FALSE); g_return_val_if_fail (DFU_IS_TARGET (target), FALSE);
g_return_val_if_fail (DFU_IS_IMAGE (image), FALSE); g_return_val_if_fail (DFU_IS_IMAGE (image), FALSE);
@ -1690,8 +1672,8 @@ dfu_target_download (DfuTarget *target, DfuImage *image,
"no image elements"); "no image elements");
return FALSE; return FALSE;
} }
for (i = 0; i < elements->len; i++) { for (guint i = 0; i < elements->len; i++) {
element = dfu_image_get_element (image, (guint8) i); DfuElement *element = dfu_image_get_element (image, (guint8) i);
g_debug ("downloading element at 0x%04x", g_debug ("downloading element at 0x%04x",
dfu_element_get_address (element)); dfu_element_get_address (element));

View File

@ -51,11 +51,10 @@ typedef struct {
static void static void
dfu_tool_print_indent (const gchar *title, const gchar *message, guint indent) dfu_tool_print_indent (const gchar *title, const gchar *message, guint indent)
{ {
gsize i; for (gsize i = 0; i < indent; i++)
for (i = 0; i < indent; i++)
g_print (" "); g_print (" ");
g_print ("%s:", title); g_print ("%s:", title);
for (i = strlen (title) + indent; i < 15; i++) for (gsize i = strlen (title) + indent; i < 15; i++)
g_print (" "); g_print (" ");
g_print ("%s\n", message); g_print ("%s\n", message);
} }
@ -106,8 +105,6 @@ dfu_tool_add (GPtrArray *array,
const gchar *description, const gchar *description,
FuUtilPrivateCb callback) FuUtilPrivateCb callback)
{ {
guint i;
FuUtilItem *item;
g_auto(GStrv) names = NULL; g_auto(GStrv) names = NULL;
g_return_if_fail (name != NULL); g_return_if_fail (name != NULL);
@ -116,8 +113,8 @@ dfu_tool_add (GPtrArray *array,
/* add each one */ /* add each one */
names = g_strsplit (name, ",", -1); names = g_strsplit (name, ",", -1);
for (i = 0; names[i] != NULL; i++) { for (guint i = 0; names[i] != NULL; i++) {
item = g_new0 (FuUtilItem, 1); FuUtilItem *item = g_new0 (FuUtilItem, 1);
item->name = g_strdup (names[i]); item->name = g_strdup (names[i]);
if (i == 0) { if (i == 0) {
item->description = g_strdup (description); item->description = g_strdup (description);
@ -135,8 +132,6 @@ dfu_tool_add (GPtrArray *array,
static gchar * static gchar *
dfu_tool_get_descriptions (GPtrArray *array) dfu_tool_get_descriptions (GPtrArray *array)
{ {
guint i;
gsize j;
gsize len; gsize len;
const gsize max_len = 31; const gsize max_len = 31;
FuUtilItem *item; FuUtilItem *item;
@ -144,7 +139,7 @@ dfu_tool_get_descriptions (GPtrArray *array)
/* print each command */ /* print each command */
string = g_string_new (""); string = g_string_new ("");
for (i = 0; i < array->len; i++) { for (guint i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i); item = g_ptr_array_index (array, i);
g_string_append (string, " "); g_string_append (string, " ");
g_string_append (string, item->name); g_string_append (string, item->name);
@ -155,13 +150,13 @@ dfu_tool_get_descriptions (GPtrArray *array)
len += strlen (item->arguments) + 1; len += strlen (item->arguments) + 1;
} }
if (len < max_len) { if (len < max_len) {
for (j = len; j < max_len + 1; j++) for (guint j = len; j < max_len + 1; j++)
g_string_append_c (string, ' '); g_string_append_c (string, ' ');
g_string_append (string, item->description); g_string_append (string, item->description);
g_string_append_c (string, '\n'); g_string_append_c (string, '\n');
} else { } else {
g_string_append_c (string, '\n'); g_string_append_c (string, '\n');
for (j = 0; j < max_len + 1; j++) for (guint j = 0; j < max_len + 1; j++)
g_string_append_c (string, ' '); g_string_append_c (string, ' ');
g_string_append (string, item->description); g_string_append (string, item->description);
g_string_append_c (string, '\n'); g_string_append_c (string, '\n');
@ -181,12 +176,9 @@ dfu_tool_run (DfuToolPrivate *priv,
gchar **values, gchar **values,
GError **error) GError **error)
{ {
guint i;
FuUtilItem *item;
/* find command */ /* find command */
for (i = 0; i < priv->cmd_array->len; i++) { for (guint i = 0; i < priv->cmd_array->len; i++) {
item = g_ptr_array_index (priv->cmd_array, i); FuUtilItem *item = g_ptr_array_index (priv->cmd_array, i);
if (g_strcmp0 (item->name, command) == 0) if (g_strcmp0 (item->name, command) == 0)
return item->callback (priv, values, error); return item->callback (priv, values, error);
} }
@ -439,7 +431,6 @@ static GBytes *
dfu_tool_parse_hex_string (const gchar *val, GError **error) dfu_tool_parse_hex_string (const gchar *val, GError **error)
{ {
gsize result_size; gsize result_size;
guint i;
g_autofree guint8 *result = NULL; g_autofree guint8 *result = NULL;
/* sanity check */ /* sanity check */
@ -454,7 +445,7 @@ dfu_tool_parse_hex_string (const gchar *val, GError **error)
/* parse each hex byte */ /* parse each hex byte */
result_size = strlen (val) / 2; result_size = strlen (val) / 2;
result = g_malloc (result_size); result = g_malloc (result_size);
for (i = 0; i < result_size; i++) { for (guint i = 0; i < result_size; i++) {
gchar buf[3] = { "xx" }; gchar buf[3] = { "xx" };
gchar *endptr = NULL; gchar *endptr = NULL;
guint64 tmp; guint64 tmp;
@ -478,7 +469,6 @@ static guint
dfu_tool_bytes_replace (GBytes *data, GBytes *search, GBytes *replace) dfu_tool_bytes_replace (GBytes *data, GBytes *search, GBytes *replace)
{ {
gsize data_sz; gsize data_sz;
gsize i;
gsize replace_sz; gsize replace_sz;
gsize search_sz; gsize search_sz;
guint8 *data_buf; guint8 *data_buf;
@ -493,7 +483,7 @@ dfu_tool_bytes_replace (GBytes *data, GBytes *search, GBytes *replace)
g_return_val_if_fail (search_sz == replace_sz, FALSE); g_return_val_if_fail (search_sz == replace_sz, FALSE);
/* find and replace each one */ /* find and replace each one */
for (i = 0; i < data_sz - search_sz; i++) { for (gsize i = 0; i < data_sz - search_sz; i++) {
if (memcmp (data_buf + i, search_buf, search_sz) == 0) { if (memcmp (data_buf + i, search_buf, search_sz) == 0) {
g_print ("Replacing %" G_GSIZE_FORMAT " bytes @0x%04x\n", g_print ("Replacing %" G_GSIZE_FORMAT " bytes @0x%04x\n",
replace_sz, (guint) i); replace_sz, (guint) i);
@ -630,8 +620,6 @@ static gboolean
dfu_tool_replace_data (DfuToolPrivate *priv, gchar **values, GError **error) dfu_tool_replace_data (DfuToolPrivate *priv, gchar **values, GError **error)
{ {
GPtrArray *images; GPtrArray *images;
guint i;
guint j;
guint cnt = 0; guint cnt = 0;
g_autoptr(DfuFirmware) firmware = NULL; g_autoptr(DfuFirmware) firmware = NULL;
g_autoptr(GFile) file = NULL; g_autoptr(GFile) file = NULL;
@ -675,10 +663,10 @@ dfu_tool_replace_data (DfuToolPrivate *priv, gchar **values, GError **error)
/* get each data segment */ /* get each data segment */
images = dfu_firmware_get_images (firmware); images = dfu_firmware_get_images (firmware);
for (i = 0; i < images->len; i++) { for (guint i = 0; i < images->len; i++) {
DfuImage *image = g_ptr_array_index (images, i); DfuImage *image = g_ptr_array_index (images, i);
GPtrArray *elements = dfu_image_get_elements (image); GPtrArray *elements = dfu_image_get_elements (image);
for (j = 0; j < elements->len; j++) { for (guint j = 0; j < elements->len; j++) {
DfuElement *element = g_ptr_array_index (elements, j); DfuElement *element = g_ptr_array_index (elements, j);
GBytes *contents = dfu_element_get_contents (element); GBytes *contents = dfu_element_get_contents (element);
if (contents == NULL) if (contents == NULL)
@ -1020,7 +1008,6 @@ dfu_tool_merge (DfuToolPrivate *priv, gchar **values, GError **error)
guint16 pid = 0xffff; guint16 pid = 0xffff;
guint16 rel = 0xffff; guint16 rel = 0xffff;
guint16 vid = 0xffff; guint16 vid = 0xffff;
guint i;
g_autofree gchar *str_debug = NULL; g_autofree gchar *str_debug = NULL;
g_autoptr(DfuFirmware) firmware = NULL; g_autoptr(DfuFirmware) firmware = NULL;
g_autoptr(GFile) file = NULL; g_autoptr(GFile) file = NULL;
@ -1039,9 +1026,8 @@ dfu_tool_merge (DfuToolPrivate *priv, gchar **values, GError **error)
/* parse source files */ /* parse source files */
firmware = dfu_firmware_new (); firmware = dfu_firmware_new ();
dfu_firmware_set_format (firmware, DFU_FIRMWARE_FORMAT_DFUSE); dfu_firmware_set_format (firmware, DFU_FIRMWARE_FORMAT_DFUSE);
for (i = 1; values[i] != NULL; i++) { for (guint i = 1; values[i] != NULL; i++) {
GPtrArray *images; GPtrArray *images;
guint j;
g_autoptr(GFile) file_tmp = NULL; g_autoptr(GFile) file_tmp = NULL;
g_autoptr(DfuFirmware) firmware_tmp = NULL; g_autoptr(DfuFirmware) firmware_tmp = NULL;
@ -1092,7 +1078,7 @@ dfu_tool_merge (DfuToolPrivate *priv, gchar **values, GError **error)
/* add all images to destination */ /* add all images to destination */
images = dfu_firmware_get_images (firmware_tmp); images = dfu_firmware_get_images (firmware_tmp);
for (j = 0; j < images->len; j++) { for (guint j = 0; j < images->len; j++) {
DfuImage *image; DfuImage *image;
guint8 alt_id; guint8 alt_id;
@ -1720,8 +1706,6 @@ dfu_tool_decrypt (DfuToolPrivate *priv, gchar **values, GError **error)
static gboolean static gboolean
dfu_tool_watch (DfuToolPrivate *priv, gchar **values, GError **error) dfu_tool_watch (DfuToolPrivate *priv, gchar **values, GError **error)
{ {
guint i;
DfuDevice *device;
g_autoptr(DfuContext) dfu_context = NULL; g_autoptr(DfuContext) dfu_context = NULL;
g_autoptr(GMainLoop) loop = NULL; g_autoptr(GMainLoop) loop = NULL;
g_autoptr(GPtrArray) devices = NULL; g_autoptr(GPtrArray) devices = NULL;
@ -1732,8 +1716,8 @@ dfu_tool_watch (DfuToolPrivate *priv, gchar **values, GError **error)
/* print what's already attached */ /* print what's already attached */
devices = dfu_context_get_devices (dfu_context); devices = dfu_context_get_devices (dfu_context);
for (i = 0; i < devices->len; i++) { for (guint i = 0; i < devices->len; i++) {
device = g_ptr_array_index (devices, i); DfuDevice *device = g_ptr_array_index (devices, i);
dfu_tool_device_added_cb (dfu_context, device, priv); dfu_tool_device_added_cb (dfu_context, device, priv);
} }
@ -1755,7 +1739,6 @@ static gboolean
dfu_tool_dump (DfuToolPrivate *priv, gchar **values, GError **error) dfu_tool_dump (DfuToolPrivate *priv, gchar **values, GError **error)
{ {
DfuFirmwareParseFlags flags = DFU_FIRMWARE_PARSE_FLAG_NONE; DfuFirmwareParseFlags flags = DFU_FIRMWARE_PARSE_FLAG_NONE;
guint i;
/* check args */ /* check args */
if (g_strv_length (values) < 1) { if (g_strv_length (values) < 1) {
@ -1773,7 +1756,7 @@ dfu_tool_dump (DfuToolPrivate *priv, gchar **values, GError **error)
} }
/* open files */ /* open files */
for (i = 0; values[i] != NULL; i++) { for (guint i = 0; values[i] != NULL; i++) {
g_autoptr(DfuFirmware) firmware = NULL; g_autoptr(DfuFirmware) firmware = NULL;
g_autoptr(GFile) file = NULL; g_autoptr(GFile) file = NULL;
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
@ -2018,7 +2001,6 @@ dfu_tool_list_target (DfuTarget *target)
DfuCipherKind cipher_kind; DfuCipherKind cipher_kind;
GPtrArray *sectors; GPtrArray *sectors;
const gchar *tmp; const gchar *tmp;
guint i;
g_autofree gchar *alt_id = NULL; g_autofree gchar *alt_id = NULL;
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
@ -2050,7 +2032,7 @@ dfu_tool_list_target (DfuTarget *target)
/* print sector information */ /* print sector information */
sectors = dfu_target_get_sectors (target); sectors = dfu_target_get_sectors (target);
for (i = 0; i < sectors->len; i++) { for (guint i = 0; i < sectors->len; i++) {
DfuSector *sector; DfuSector *sector;
g_autofree gchar *msg = NULL; g_autofree gchar *msg = NULL;
g_autofree gchar *title = NULL; g_autofree gchar *title = NULL;
@ -2065,7 +2047,6 @@ dfu_tool_list_target (DfuTarget *target)
static gboolean static gboolean
dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error) dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error)
{ {
guint i;
g_autoptr(DfuContext) dfu_context = NULL; g_autoptr(DfuContext) dfu_context = NULL;
g_autoptr(GPtrArray) devices = NULL; g_autoptr(GPtrArray) devices = NULL;
@ -2073,13 +2054,12 @@ dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error)
dfu_context = dfu_context_new (); dfu_context = dfu_context_new ();
dfu_context_enumerate (dfu_context, NULL); dfu_context_enumerate (dfu_context, NULL);
devices = dfu_context_get_devices (dfu_context); devices = dfu_context_get_devices (dfu_context);
for (i = 0; i < devices->len; i++) { for (guint i = 0; i < devices->len; i++) {
DfuDevice *device = NULL; DfuDevice *device = NULL;
DfuTarget *target; DfuTarget *target;
GUsbDevice *dev; GUsbDevice *dev;
GPtrArray *dfu_targets; GPtrArray *dfu_targets;
const gchar *tmp; const gchar *tmp;
guint j;
guint16 transfer_size; guint16 transfer_size;
g_autofree gchar *quirks = NULL; g_autofree gchar *quirks = NULL;
g_autofree gchar *version = NULL; g_autofree gchar *version = NULL;
@ -2165,7 +2145,7 @@ dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error)
/* list targets */ /* list targets */
dfu_targets = dfu_device_get_targets (device); dfu_targets = dfu_device_get_targets (device);
for (j = 0; j < dfu_targets->len; j++) { for (guint j = 0; j < dfu_targets->len; j++) {
target = g_ptr_array_index (dfu_targets, j); target = g_ptr_array_index (dfu_targets, j);
dfu_tool_list_target (target); dfu_tool_list_target (target);
} }

View File

@ -346,7 +346,6 @@ fu_device_ebitdo_open (FuDeviceEbitdo *device, GError **error)
gdouble tmp; gdouble tmp;
guint32 version_tmp = 0; guint32 version_tmp = 0;
guint32 serial_tmp[9]; guint32 serial_tmp[9];
guint i;
g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(FuDeviceLocker) locker = NULL;
/* already open */ /* already open */
@ -417,7 +416,7 @@ fu_device_ebitdo_open (FuDeviceEbitdo *device, GError **error)
error)) { error)) {
return FALSE; return FALSE;
} }
for (i = 0; i < 9; i++) for (guint i = 0; i < 9; i++)
priv->serial[i] = GUINT32_FROM_LE (serial_tmp[i]); priv->serial[i] = GUINT32_FROM_LE (serial_tmp[i]);
/* success */ /* success */
@ -450,10 +449,8 @@ fu_device_ebitdo_write_firmware (FuDeviceEbitdo *device, GBytes *fw,
FuEbitdoFirmwareHeader *hdr; FuEbitdoFirmwareHeader *hdr;
const guint8 *payload_data; const guint8 *payload_data;
const guint chunk_sz = 32; const guint chunk_sz = 32;
guint32 offset;
guint32 payload_len; guint32 payload_len;
guint32 serial_new[3]; guint32 serial_new[3];
guint i;
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
const guint32 app_key_index[16] = { const guint32 app_key_index[16] = {
0x186976e5, 0xcac67acd, 0x38f27fee, 0x0a4948f1, 0x186976e5, 0xcac67acd, 0x38f27fee, 0x0a4948f1,
@ -488,7 +485,7 @@ fu_device_ebitdo_write_firmware (FuDeviceEbitdo *device, GBytes *fw,
} }
/* check if this is firmware */ /* check if this is firmware */
for (i = 0; i < 4; i++) { for (guint i = 0; i < 4; i++) {
if (hdr->reserved[i] != 0x0) { if (hdr->reserved[i] != 0x0) {
g_set_error (error, g_set_error (error,
G_IO_ERROR, G_IO_ERROR,
@ -525,7 +522,7 @@ fu_device_ebitdo_write_firmware (FuDeviceEbitdo *device, GBytes *fw,
/* flash the firmware in 32 byte blocks */ /* flash the firmware in 32 byte blocks */
payload_data = g_bytes_get_data (fw, NULL); payload_data = g_bytes_get_data (fw, NULL);
payload_data += sizeof(FuEbitdoFirmwareHeader); payload_data += sizeof(FuEbitdoFirmwareHeader);
for (offset = 0; offset < payload_len; offset += chunk_sz) { for (guint32 offset = 0; offset < payload_len; offset += chunk_sz) {
if (g_getenv ("FU_EBITDO_DEBUG") != NULL) { if (g_getenv ("FU_EBITDO_DEBUG") != NULL) {
g_debug ("writing %u bytes to 0x%04x of 0x%04x", g_debug ("writing %u bytes to 0x%04x of 0x%04x",
chunk_sz, offset, payload_len); chunk_sz, offset, payload_len);
@ -666,7 +663,6 @@ fu_device_ebitdo_new (GUsbDevice *usb_device)
{ {
FuDeviceEbitdo *device; FuDeviceEbitdo *device;
FuDeviceEbitdoPrivate *priv; FuDeviceEbitdoPrivate *priv;
guint j;
const FuEbitdoVidPid vidpids[] = { const FuEbitdoVidPid vidpids[] = {
/* legacy VIDs */ /* legacy VIDs */
{ 0x0483, 0x5750, FU_DEVICE_EBITDO_KIND_BOOTLOADER }, { 0x0483, 0x5750, FU_DEVICE_EBITDO_KIND_BOOTLOADER },
@ -690,7 +686,7 @@ fu_device_ebitdo_new (GUsbDevice *usb_device)
}; };
/* set kind */ /* set kind */
for (j = 0; vidpids[j].vid != 0x0000; j++) { for (guint j = 0; vidpids[j].vid != 0x0000; j++) {
if (g_usb_device_get_vid (usb_device) != vidpids[j].vid) if (g_usb_device_get_vid (usb_device) != vidpids[j].vid)
continue; continue;
if (g_usb_device_get_pid (usb_device) != vidpids[j].pid) if (g_usb_device_get_pid (usb_device) != vidpids[j].pid)

View File

@ -40,7 +40,6 @@ int
main (int argc, char **argv) main (int argc, char **argv)
{ {
gsize len; gsize len;
guint i;
g_autofree guint8 *data = NULL; g_autofree guint8 *data = NULL;
g_autoptr(FuDeviceEbitdo) dev = NULL; g_autoptr(FuDeviceEbitdo) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(FuDeviceLocker) locker = NULL;
@ -65,7 +64,7 @@ main (int argc, char **argv)
} }
g_usb_context_enumerate (usb_ctx); g_usb_context_enumerate (usb_ctx);
devices = g_usb_context_get_devices (usb_ctx); devices = g_usb_context_get_devices (usb_ctx);
for (i = 0; i < devices->len; i++) { for (guint i = 0; i < devices->len; i++) {
GUsbDevice *usb_dev_tmp = g_ptr_array_index (devices, i); GUsbDevice *usb_dev_tmp = g_ptr_array_index (devices, i);
g_autoptr(FuDeviceEbitdo) dev_tmp = fu_device_ebitdo_new (usb_dev_tmp); g_autoptr(FuDeviceEbitdo) dev_tmp = fu_device_ebitdo_new (usb_dev_tmp);
if (dev_tmp != NULL) { if (dev_tmp != NULL) {
@ -92,7 +91,7 @@ main (int argc, char **argv)
g_print ("Device Firmware Ver: %s\n", g_print ("Device Firmware Ver: %s\n",
fu_device_get_version (FU_DEVICE (dev))); fu_device_get_version (FU_DEVICE (dev)));
g_print ("Device Verification ID:\n"); g_print ("Device Verification ID:\n");
for (i = 0; i < 9; i++) for (guint i = 0; i < 9; i++)
g_print ("\t%u = 0x%08x\n", i, fu_device_ebitdo_get_serial(dev)[i]); g_print ("\t%u = 0x%08x\n", i, fu_device_ebitdo_get_serial(dev)[i]);
/* not in bootloader mode, so print what to do */ /* not in bootloader mode, so print what to do */

View File

@ -137,9 +137,6 @@ fu_plugin_synaptics_scan_cascade (FuPlugin *plugin,
g_autofree gchar *dev_id_str = NULL; g_autofree gchar *dev_id_str = NULL;
FuDevice *fu_dev = NULL; FuDevice *fu_dev = NULL;
const gchar *aux_node; const gchar *aux_node;
guint8 layer = 0;
guint16 rad = 0;
guint8 j;
aux_node = synapticsmst_device_get_aux_node (device); aux_node = synapticsmst_device_get_aux_node (device);
if (!synapticsmst_device_open (device, error)) { if (!synapticsmst_device_open (device, error)) {
@ -149,9 +146,9 @@ fu_plugin_synaptics_scan_cascade (FuPlugin *plugin,
return FALSE; return FALSE;
} }
for (j = 0; j < 2; j++) { for (guint8 j = 0; j < 2; j++) {
layer = synapticsmst_device_get_layer (device) + 1; guint8 layer = synapticsmst_device_get_layer (device) + 1;
rad = synapticsmst_device_get_rad (device) | (j << (2 * (layer - 1))); guint16 rad = synapticsmst_device_get_rad (device) | (j << (2 * (layer - 1)));
dev_id_str = g_strdup_printf ("MST-REMOTE-%s-%u-%u", dev_id_str = g_strdup_printf ("MST-REMOTE-%s-%u-%u",
aux_node, layer, rad); aux_node, layer, rad);
fu_dev = fu_plugin_cache_lookup (plugin, dev_id_str); fu_dev = fu_plugin_cache_lookup (plugin, dev_id_str);

View File

@ -95,9 +95,7 @@ synapticsmst_tool_add (GPtrArray *array,
const gchar *description, const gchar *description,
FuUtilPrivateCb callback) FuUtilPrivateCb callback)
{ {
guint i; g_auto(GStrv) names = NULL;
FuUtilItem *item;
g_auto (GStrv) names = NULL;
g_return_if_fail (name != NULL); g_return_if_fail (name != NULL);
g_return_if_fail (description != NULL); g_return_if_fail (description != NULL);
@ -105,8 +103,8 @@ synapticsmst_tool_add (GPtrArray *array,
/* add each one */ /* add each one */
names = g_strsplit (name, ",", -1); names = g_strsplit (name, ",", -1);
for (i = 0; names[i] != NULL; i++) { for (guint i = 0; names[i] != NULL; i++) {
item = g_new0 (FuUtilItem, 1); FuUtilItem *item = g_new0 (FuUtilItem, 1);
item->name = g_strdup (names[i]); item->name = g_strdup (names[i]);
if (i == 0) { if (i == 0) {
item->description = g_strdup (description); item->description = g_strdup (description);
@ -124,44 +122,41 @@ synapticsmst_tool_add (GPtrArray *array,
static gchar * static gchar *
synapticsmst_tool_get_descriptions (GPtrArray *array) synapticsmst_tool_get_descriptions (GPtrArray *array)
{ {
guint i;
gsize j;
gsize len; gsize len;
const gsize max_len = 31; const gsize max_len = 31;
FuUtilItem *item; GString *str;
GString *string;
/* print each command */ /* print each command */
string = g_string_new (""); str = g_string_new ("");
for (i = 0; i < array->len; i++) { for (guint i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i); FuUtilItem *item = g_ptr_array_index (array, i);
g_string_append (string, " "); g_string_append (str, " ");
g_string_append (string, item->name); g_string_append (str, item->name);
len = strlen (item->name) + 2; len = strlen (item->name) + 2;
if (item->arguments != NULL) { if (item->arguments != NULL) {
g_string_append (string, " "); g_string_append (str, " ");
g_string_append (string, item->arguments); g_string_append (str, item->arguments);
len += strlen (item->arguments) + 1; len += strlen (item->arguments) + 1;
} }
if (len < max_len) { if (len < max_len) {
for (j = len; j < max_len + 1; j++) for (gsize j = len; j < max_len + 1; j++)
g_string_append_c (string, ' '); g_string_append_c (str, ' ');
g_string_append (string, item->description); g_string_append (str, item->description);
g_string_append_c (string, '\n'); g_string_append_c (str, '\n');
} else { } else {
g_string_append_c (string, '\n'); g_string_append_c (str, '\n');
for (j = 0; j < max_len + 1; j++) for (gsize j = 0; j < max_len + 1; j++)
g_string_append_c (string, ' '); g_string_append_c (str, ' ');
g_string_append (string, item->description); g_string_append (str, item->description);
g_string_append_c (string, '\n'); g_string_append_c (str, '\n');
} }
} }
/* remove trailing newline */ /* remove trailing newline */
if (string->len > 0) if (str->len > 0)
g_string_set_size (string, string->len - 1); g_string_set_size (str, str->len - 1);
return g_string_free (string, FALSE); return g_string_free (str, FALSE);
} }
static gboolean static gboolean
@ -344,12 +339,9 @@ synapticsmst_tool_run (SynapticsMSTToolPrivate *priv,
guint8 device_index, guint8 device_index,
GError **error) GError **error)
{ {
guint i;
FuUtilItem *item;
/* find command */ /* find command */
for (i = 0; i < priv->cmd_array->len; i++) { for (guint i = 0; i < priv->cmd_array->len; i++) {
item = g_ptr_array_index (priv->cmd_array, i); FuUtilItem *item = g_ptr_array_index (priv->cmd_array, i);
if (g_strcmp0 (item->name, command) == 0) if (g_strcmp0 (item->name, command) == 0)
return item->callback (priv, values, device_index, error); return item->callback (priv, values, device_index, error);
} }

View File

@ -221,7 +221,6 @@ mock_tree_init (MockDevice *device)
static void static void
mock_tree_dump (const MockTree *node, int level) mock_tree_dump (const MockTree *node, int level)
{ {
guint i;
if (node->path) { if (node->path) {
g_debug ("%*s * %s [%s] at %s", level, " ", g_debug ("%*s * %s [%s] at %s", level, " ",
node->device->name, node->uuid, node->path); node->device->name, node->uuid, node->path);
@ -234,7 +233,7 @@ mock_tree_dump (const MockTree *node, int level)
node->device->name, node->uuid, node->sysfs_id); node->device->name, node->uuid, node->sysfs_id);
} }
for (i = 0; i < node->children->len; i++) { for (guint i = 0; i < node->children->len; i++) {
const MockTree *child = g_ptr_array_index (node->children, i); const MockTree *child = g_ptr_array_index (node->children, i);
mock_tree_dump (child, level + 2); mock_tree_dump (child, level + 2);
} }
@ -291,12 +290,10 @@ mock_tree_contains (const MockTree *node,
MockTreePredicate predicate, MockTreePredicate predicate,
gpointer data) gpointer data)
{ {
guint i;
if (predicate (node, data)) if (predicate (node, data))
return node; return node;
for (i = 0; i < node->children->len; i++) { for (guint i = 0; i < node->children->len; i++) {
const MockTree *child; const MockTree *child;
const MockTree *match; const MockTree *match;
@ -630,12 +627,11 @@ static void
mock_tree_detach (MockTree *node) mock_tree_detach (MockTree *node)
{ {
UMockdevTestbed *bed; UMockdevTestbed *bed;
guint i;
if (mock_tree_node_is_detached (node, NULL)) if (mock_tree_node_is_detached (node, NULL))
return; return;
for (i = 0; i < node->children->len; i++) { for (guint i = 0; i < node->children->len; i++) {
MockTree *child = g_ptr_array_index (node->children, i); MockTree *child = g_ptr_array_index (node->children, i);
mock_tree_detach (child); mock_tree_detach (child);
g_free (child->sysfs_parent); g_free (child->sysfs_parent);

View File

@ -59,11 +59,10 @@ fu_fuzzer_rom_parse (const gchar *fn, GError **error)
static gboolean static gboolean
fu_fuzzer_write_files (GHashTable *hash, GError **error) fu_fuzzer_write_files (GHashTable *hash, GError **error)
{ {
GList *l;
GString *str; GString *str;
g_autoptr(GList) keys = g_hash_table_get_keys (hash); g_autoptr(GList) keys = g_hash_table_get_keys (hash);
for (l = keys; l != NULL; l = l->next) { for (GList *l = keys; l != NULL; l = l->next) {
g_autofree gchar *filename = NULL; g_autofree gchar *filename = NULL;
const gchar *fn = l->data; const gchar *fn = l->data;
filename = g_build_filename ("fuzzing", fn, NULL); filename = g_build_filename ("fuzzing", fn, NULL);
@ -164,7 +163,6 @@ fu_fuzzer_rom_create (GError **error)
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
guint i;
gboolean verbose = FALSE; gboolean verbose = FALSE;
g_autoptr(GError) error_parse = NULL; g_autoptr(GError) error_parse = NULL;
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = NULL;
@ -190,7 +188,7 @@ main (int argc, char *argv[])
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE); g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
if (g_strcmp0 (argv[1], "rom") == 0) { if (g_strcmp0 (argv[1], "rom") == 0) {
gboolean all_successful = TRUE; gboolean all_successful = TRUE;
for (i = 2; i < (guint) argc; i++) { for (guint i = 2; i < (guint) argc; i++) {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
if (!fu_fuzzer_rom_parse (argv[i], &error)) { if (!fu_fuzzer_rom_parse (argv[i], &error)) {
g_print ("Failed to parse %s: %s\n", g_print ("Failed to parse %s: %s\n",

View File

@ -82,8 +82,6 @@ lu_tool_add (GPtrArray *array,
const gchar *description, const gchar *description,
FuLuToolPrivateCb callback) FuLuToolPrivateCb callback)
{ {
guint i;
FuLuToolItem *item;
g_auto(GStrv) names = NULL; g_auto(GStrv) names = NULL;
g_return_if_fail (name != NULL); g_return_if_fail (name != NULL);
@ -92,8 +90,8 @@ lu_tool_add (GPtrArray *array,
/* add each one */ /* add each one */
names = g_strsplit (name, ",", -1); names = g_strsplit (name, ",", -1);
for (i = 0; names[i] != NULL; i++) { for (guint i = 0; names[i] != NULL; i++) {
item = g_new0 (FuLuToolItem, 1); FuLuToolItem *item = g_new0 (FuLuToolItem, 1);
item->name = g_strdup (names[i]); item->name = g_strdup (names[i]);
if (i == 0) { if (i == 0) {
item->description = g_strdup (description); item->description = g_strdup (description);
@ -109,44 +107,41 @@ lu_tool_add (GPtrArray *array,
static gchar * static gchar *
lu_tool_get_descriptions (GPtrArray *array) lu_tool_get_descriptions (GPtrArray *array)
{ {
guint i;
gsize j;
gsize len;
const gsize max_len = 31; const gsize max_len = 31;
FuLuToolItem *item; GString *str;
GString *string;
/* print each command */ /* print each command */
string = g_string_new (""); str = g_string_new ("");
for (i = 0; i < array->len; i++) { for (guint i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i); FuLuToolItem *item = g_ptr_array_index (array, i);
g_string_append (string, " "); gsize len;
g_string_append (string, item->name); g_string_append (str, " ");
g_string_append (str, item->name);
len = strlen (item->name) + 2; len = strlen (item->name) + 2;
if (item->arguments != NULL) { if (item->arguments != NULL) {
g_string_append (string, " "); g_string_append (str, " ");
g_string_append (string, item->arguments); g_string_append (str, item->arguments);
len += strlen (item->arguments) + 1; len += strlen (item->arguments) + 1;
} }
if (len < max_len) { if (len < max_len) {
for (j = len; j < max_len + 1; j++) for (guint j = len; j < max_len + 1; j++)
g_string_append_c (string, ' '); g_string_append_c (str, ' ');
g_string_append (string, item->description); g_string_append (str, item->description);
g_string_append_c (string, '\n'); g_string_append_c (str, '\n');
} else { } else {
g_string_append_c (string, '\n'); g_string_append_c (str, '\n');
for (j = 0; j < max_len + 1; j++) for (guint j = 0; j < max_len + 1; j++)
g_string_append_c (string, ' '); g_string_append_c (str, ' ');
g_string_append (string, item->description); g_string_append (str, item->description);
g_string_append_c (string, '\n'); g_string_append_c (str, '\n');
} }
} }
/* remove trailing newline */ /* remove trailing newline */
if (string->len > 0) if (str->len > 0)
g_string_set_size (string, string->len - 1); g_string_set_size (str, str->len - 1);
return g_string_free (string, FALSE); return g_string_free (str, FALSE);
} }
static gboolean static gboolean
@ -155,12 +150,9 @@ lu_tool_run (FuLuToolPrivate *priv,
gchar **values, gchar **values,
GError **error) GError **error)
{ {
guint i;
FuLuToolItem *item;
/* find command */ /* find command */
for (i = 0; i < priv->cmd_array->len; i++) { for (guint i = 0; i < priv->cmd_array->len; i++) {
item = g_ptr_array_index (priv->cmd_array, i); FuLuToolItem *item = g_ptr_array_index (priv->cmd_array, i);
if (g_strcmp0 (item->name, command) == 0) if (g_strcmp0 (item->name, command) == 0)
return item->callback (priv, values, error); return item->callback (priv, values, error);
} }