mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-07 09:50:28 +01:00
cli: use NM_CMP*() macros for compare_aps() in "clients/cli/devices.c"
The compare pattern seems simple, but seems error prone and subtle. NM_CMP*() avoids that. For example, nm_access_point_get_strength() returns an uint8_t. C will promote those values to "int" before doing the subtraction. Likewise, nm_access_point_get_frequency() returns a uint32_t. This gets promoted to unsigned int when doing the subtraction. Afterwards, that is converted to a signed int. So both cases were in fact correct. But such things are not obvious. Also, as fallback sort by D-Bus path. While that is not semantically useful, we should use a defined sort order.
This commit is contained in:
parent
652de3b8d2
commit
ca4b530742
1 changed files with 7 additions and 8 deletions
|
|
@ -1101,17 +1101,16 @@ compare_aps (gconstpointer a, gconstpointer b, gpointer user_data)
|
|||
{
|
||||
NMAccessPoint *apa = *(NMAccessPoint **)a;
|
||||
NMAccessPoint *apb = *(NMAccessPoint **)b;
|
||||
int cmp;
|
||||
|
||||
cmp = nm_access_point_get_strength (apb) - nm_access_point_get_strength (apa);
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
NM_CMP_DIRECT (nm_access_point_get_strength (apb), nm_access_point_get_strength (apa));
|
||||
NM_CMP_DIRECT (nm_access_point_get_frequency (apa), nm_access_point_get_frequency (apb));
|
||||
NM_CMP_DIRECT (nm_access_point_get_max_bitrate (apb), nm_access_point_get_max_bitrate (apa));
|
||||
|
||||
cmp = nm_access_point_get_frequency (apa) - nm_access_point_get_frequency (apb);
|
||||
if (cmp != 0)
|
||||
return cmp;
|
||||
/* as fallback, just give it some stable order and use the D-Bus path (literally). */
|
||||
NM_CMP_DIRECT_STRCMP0 (nm_object_get_path (NM_OBJECT (apa)),
|
||||
nm_object_get_path (NM_OBJECT (apb)));
|
||||
|
||||
return nm_access_point_get_max_bitrate (apb) - nm_access_point_get_max_bitrate (apa);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static GPtrArray *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue