summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-06-22 18:11:24 +0200
committerThomas Haller <thaller@redhat.com>2015-07-01 15:47:29 +0200
commite7f3ccf7cdb5b5d1765b434c71cf622a6a31a966 (patch)
tree1e256a298a5aebc1f259f9134fc9d4f032bf1494
parent7594e3122045081050c031a5e8b1179d1cd561df (diff)
downloadNetworkManager-e7f3ccf7cdb5b5d1765b434c71cf622a6a31a966.tar.gz
core: minor refactoring iterating and removing list of routes
The previous version causes an unsigned integer underflow. That is not wrong, but still change it. Also use g_array_remove_index_fast() because the list of routes is unsorted anyway.
-rw-r--r--src/nm-ip4-config.c7
-rw-r--r--src/nm-ip6-config.c7
2 files changed, 8 insertions, 6 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index a3ef072b90..b134d6034d 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -233,7 +233,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
/* Extract gateway from default route */
old_gateway = priv->gateway;
- for (i = 0; i < priv->routes->len; i++) {
+ for (i = 0; i < priv->routes->len; ) {
const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i);
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
@@ -243,9 +243,10 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
}
has_gateway = TRUE;
/* Remove the default route from the list */
- g_array_remove_index (priv->routes, i);
- i--;
+ g_array_remove_index_fast (priv->routes, i);
+ continue;
}
+ i++;
}
/* we detect the route metric based on the default route. All non-default
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index dcb318b7e3..696a998df6 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -346,7 +346,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
/* Extract gateway from default route */
old_gateway = priv->gateway;
- for (i = 0; i < priv->routes->len; i++) {
+ for (i = 0; i < priv->routes->len; ) {
const NMPlatformIP6Route *route = &g_array_index (priv->routes, NMPlatformIP6Route, i);
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
@@ -356,9 +356,10 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
}
has_gateway = TRUE;
/* Remove the default route from the list */
- g_array_remove_index (priv->routes, i);
- i--;
+ g_array_remove_index_fast (priv->routes, i);
+ continue;
}
+ i++;
}
/* we detect the route metric based on the default route. All non-default