device/wifi: cleanup ssids_options_to_ptrarray()

- use proper gsize type to hold g_variant_n_children()

- use cleanup attribute for GPtrArray

- move variables inside nested scope where they are used
This commit is contained in:
Thomas Haller 2020-01-04 11:44:47 +01:00
parent 023dc9646c
commit e6d256fe81

View file

@ -1074,10 +1074,9 @@ _hw_addr_set_scanning (NMDeviceWifi *self, gboolean do_reset)
static GPtrArray *
ssids_options_to_ptrarray (GVariant *value, GError **error)
{
GPtrArray *ssids = NULL;
const guint8 *bytes;
gsize len;
int num_ssids, i;
gs_unref_ptrarray GPtrArray *ssids = NULL;
gsize num_ssids;
gsize i;
nm_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("aay")));
@ -1094,6 +1093,8 @@ ssids_options_to_ptrarray (GVariant *value, GError **error)
ssids = g_ptr_array_new_full (num_ssids, (GDestroyNotify) g_bytes_unref);
for (i = 0; i < num_ssids; i++) {
gs_unref_variant GVariant *v = NULL;
gsize len;
const guint8 *bytes;
v = g_variant_get_child_value (value, i);
bytes = g_variant_get_fixed_array (v, &len, sizeof (guint8));
@ -1101,15 +1102,15 @@ ssids_options_to_ptrarray (GVariant *value, GError **error)
g_set_error (error,
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_ALLOWED,
"SSID at index %d more than 32 bytes", i);
g_ptr_array_unref (ssids);
"SSID at index %d more than 32 bytes", (int) i);
return NULL;
}
g_ptr_array_add (ssids, g_bytes_new (bytes, len));
}
}
return ssids;
return g_steal_pointer (&ssids);
}
GPtrArray *