device: don't limit try count in nm_device_ethernet_utils_get_default_wired_name()

The limit of trying up to 10000 was arbitrary. In practice, we are not expected
that we need that many searches. If that would be the case (and we would have
10000 conflicting connections that take all the names), then we anyway would
need to refactor the code not to scale with O(n^2).

Replace the arbitrary limit with an even larger one. The new limit is so
large that in practice it's impossible to reach it.
This commit is contained in:
Thomas Haller
2018-08-27 11:36:51 +02:00
parent 72de0afa35
commit 3a99c343d8

View File

@@ -32,7 +32,7 @@ nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connection
int i; int i;
/* Find the next available unique connection name */ /* Find the next available unique connection name */
for (i = 1; i <= 10000; i++) { for (i = 1; i <= G_MAXINT; i++) {
temp = g_strdup_printf (_("Wired connection %d"), i); temp = g_strdup_printf (_("Wired connection %d"), i);
for (j = 0; connections[j]; j++) { for (j = 0; connections[j]; j++) {
if (nm_streq0 (nm_connection_get_id (connections[j]), temp)) { if (nm_streq0 (nm_connection_get_id (connections[j]), temp)) {
@@ -44,7 +44,6 @@ nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connection
next: next:
; ;
} }
return NULL; return NULL;
} }