From: Gert Doering Date: Tue, 27 Jul 2021 16:37:41 +0200 Message-Id: <20210727143741.29039-1-gert@...1296...> MIME-Version: 1.0 Subject: [Openvpn-devel] [PATCH] Use more C99 initialization in add_route/add_route_ipv6(). List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: openvpn-devel@lists.sourceforge.net This gets rid of a few #ifdef and also removes the need for commit a11bea18b1c93 (argv is only initialized after the early exit check on RT_DEFINED). Signed-off-by: Gert Doering --- src/openvpn/route.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/openvpn/route.c b/src/openvpn/route.c index e429e8c0..bec5d6ff 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1570,32 +1570,24 @@ add_route(struct route_ipv4 *r, const struct env_set *es, openvpn_net_ctx_t *ctx) { - struct gc_arena gc; - struct argv argv = argv_new(); -#if !defined(TARGET_LINUX) - const char *network; -#if !defined(TARGET_AIX) - const char *netmask; -#endif - const char *gateway; -#endif bool status = false; int is_local_route; if (!(r->flags & RT_DEFINED)) { - argv_free(&argv); return; } + struct argv argv = argv_new(); + struct gc_arena gc; gc_init(&gc); #if !defined(TARGET_LINUX) - network = print_in_addr_t(r->network, 0, &gc); + const char *network = print_in_addr_t(r->network, 0, &gc); #if !defined(TARGET_AIX) - netmask = print_in_addr_t(r->netmask, 0, &gc); + const char *netmask = print_in_addr_t(r->netmask, 0, &gc); #endif - gateway = print_in_addr_t(r->gateway, 0, &gc); + const char *gateway = print_in_addr_t(r->gateway, 0, &gc); #endif is_local_route = local_route(r->network, r->netmask, r->gateway, rgi); @@ -1879,23 +1871,18 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, openvpn_net_ctx_t *ctx) { struct gc_arena gc; - struct argv argv = argv_new(); - const char *network; - const char *gateway; bool status = false; const char *device = tt->actual_name; -#if defined(TARGET_LINUX) - int metric; -#endif bool gateway_needed = false; if (!(r6->flags & RT_DEFINED) ) { - argv_free(&argv); return; } + struct argv argv = argv_new(); + #ifndef _WIN32 if (r6->iface != NULL) /* vpn server special route */ { @@ -1910,9 +1897,8 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, gc_init(&gc); route_ipv6_clear_host_bits(r6); - - network = print_in6_addr( r6->network, 0, &gc); - gateway = print_in6_addr( r6->gateway, 0, &gc); + const char *network = print_in6_addr( r6->network, 0, &gc); + const char *gateway = print_in6_addr( r6->gateway, 0, &gc); #if defined(TARGET_DARWIN) \ || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ @@ -1963,7 +1949,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, } #if defined(TARGET_LINUX) - metric = -1; + int metric = -1; if ((r6->flags & RT_METRIC_DEFINED) && (r6->metric > 0)) { metric = r6->metric; -- 2.26.3