From aff443013640ba783c89c9032ebd5a557f2fc11e Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sun, 3 Jun 2018 04:18:23 +0200 Subject: network: avoid temporary variables for parsing, use TAKE_PTR (#9166) We don't need a temporary variable when parsing just one number, because our parsing functions do not touch the output variable on error. TAKE_PTR is more expressive than 'n = NULL'. --- src/network/networkd-route.c | 45 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) (limited to 'src/network/networkd-route.c') diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index a5303dafa..369e45342 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -716,7 +716,7 @@ int config_parse_gateway( n->family = f; n->gw = buffer; - n = NULL; + TAKE_PTR(n); return 0; } @@ -757,7 +757,7 @@ int config_parse_preferred_src( n->family = f; n->prefsrc = buffer; - n = NULL; + TAKE_PTR(n); return 0; } @@ -813,8 +813,7 @@ int config_parse_destination( } else assert_not_reached(lvalue); - n = NULL; - + TAKE_PTR(n); return 0; } @@ -832,7 +831,6 @@ int config_parse_route_priority( Network *network = userdata; _cleanup_(route_freep) Route *n = NULL; - uint32_t k; int r; assert(filename); @@ -845,16 +843,14 @@ int config_parse_route_priority( if (r < 0) return r; - r = safe_atou32(rvalue, &k); + r = safe_atou32(rvalue, &n->priority); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, r, "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue); return 0; } - n->priority = k; - n = NULL; - + TAKE_PTR(n); return 0; } @@ -895,8 +891,7 @@ int config_parse_route_scope( return 0; } - n = NULL; - + TAKE_PTR(n); return 0; } @@ -914,7 +909,6 @@ int config_parse_route_table( _cleanup_(route_freep) Route *n = NULL; Network *network = userdata; - uint32_t k; int r; assert(filename); @@ -927,16 +921,14 @@ int config_parse_route_table( if (r < 0) return r; - r = safe_atou32(rvalue, &k); + r = safe_atou32(rvalue, &n->table); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, r, "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue); return 0; } - n->table = k; - n = NULL; - + TAKE_PTR(n); return 0; } @@ -974,8 +966,7 @@ int config_parse_gateway_onlink( } SET_FLAG(n->flags, RTNH_F_ONLINK, r); - n = NULL; - + TAKE_PTR(n); return 0; } @@ -1010,8 +1001,7 @@ int config_parse_ipv6_route_preference( return 0; } - n = NULL; - + TAKE_PTR(n); return 0; } @@ -1049,8 +1039,7 @@ int config_parse_route_protocol( } } - n = NULL; - + TAKE_PTR(n); return 0; } @@ -1087,8 +1076,7 @@ int config_parse_route_type( return 0; } - n = NULL; - + TAKE_PTR(n); return 0; } @@ -1135,8 +1123,7 @@ int config_parse_tcp_window( return 0; } - n = NULL; - + TAKE_PTR(n); return 0; } @@ -1173,8 +1160,7 @@ int config_parse_quickack( } n->quickack = !!k; - n = NULL; - + TAKE_PTR(n); return 0; } @@ -1208,7 +1194,6 @@ int config_parse_route_mtu( if (r < 0) return r; - n = NULL; - + TAKE_PTR(n); return 0; } -- cgit v1.2.3-65-gdbad