Hi Daniel,
On 12/11/20 4:11 PM, Daniel Wagner wrote:
gcc complains 'struct vpn_route' is declared within the code
section.
By declaring it at the begin of the function we can also avoid the
additional helper variables.
---
plugins/vpn.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/plugins/vpn.c b/plugins/vpn.c
index 94d6e8591d88..3ed9c32268b4 100644
--- a/plugins/vpn.c
+++ b/plugins/vpn.c
@@ -1523,32 +1523,29 @@ static int save_route(GHashTable *routes, int family, const char
*network,
static int add_network_route(struct connection_data *data)
{
- char *network = NULL;
- char *gateway = NULL;
- char *netmask = NULL;
- int family;
+ struct vpn_route rt = { 0, };
int err;
if (!data)
return -EINVAL;
- family = connman_provider_get_family(data->provider);
- switch (family) {
+ rt.family = connman_provider_get_family(data->provider);
+ switch (rt.family) {
case PF_INET:
- err = connman_inet_get_route_addresses(data->index, &network,
- &netmask, &gateway);
+ err = connman_inet_get_route_addresses(data->index,
+ &rt.network, &rt.netmask, &rt.gateway);
break;
case PF_INET6:
err = connman_inet_ipv6_get_route_addresses(data->index,
- &network, &netmask, &gateway);
+ &rt.network, &rt.netmask, &rt.gateway);
break;
default:
- connman_error("invalid protocol family %d", family);
+ connman_error("invalid protocol family %d", rt.family);
return -EINVAL;
}
DBG("network %s gateway %s netmask %s for provider %p",
- network, gateway, netmask,
+ rt.network, rt.gateway, rt.netmask,
data->provider);
if (err) {
@@ -1557,21 +1554,20 @@ static int add_network_route(struct connection_data *data)
goto out;
}
- err = save_route(data->server_routes, family, network, netmask,
- gateway);
+ err = save_route(data->server_routes, rt.family, rt.network, rt.netmask,
+ rt.gateway);
if (err) {
connman_warn("failed to add network route for provider"
"%p", data->provider);
goto out;
}
- struct vpn_route route = { family, network, netmask, gateway };
- set_route(data, &route);
+ set_route(data, &rt);
out:
- g_free(network);
- g_free(gateway);
- g_free(netmask);
+ g_free(rt.network);
+ g_free(rt.netmask);
+ g_free(rt.gateway);
return 0;
}
I guess I have too old gcc (8.3.0) for these to be warned about, sorry.
Favoring stability over bleeding edge has its drawbacks. Maybe I should
setup a virtual machine with a bleeding edge, as even backports do not
give a newer gcc than the one I have.
Just out of curiosity, what version of gcc are you using with tes builds?
BR,
Jussi