]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/generator/network-generator.c
tree-wide: use ASSERT_PTR more
[thirdparty/systemd.git] / src / network / generator / network-generator.c
index a1b5511338c4c4a4726e52ebfa842bf9ad912a36..1090934bfc15e03d00e2503b4b62a1429d7f8bf8 100644 (file)
@@ -1004,10 +1004,9 @@ static int parse_cmdline_ifname_policy(Context *context, const char *key, const
 }
 
 int parse_cmdline_item(const char *key, const char *value, void *data) {
-        Context *context = data;
+        Context *context = ASSERT_PTR(data);
 
         assert(key);
-        assert(data);
 
         if (streq(key, "ip"))
                 return parse_cmdline_ip(context, key, value);
@@ -1081,48 +1080,23 @@ void context_clear(Context *context) {
 }
 
 static int address_dump(Address *address, FILE *f) {
-        _cleanup_free_ char *addr = NULL, *peer = NULL;
-        int r;
-
-        r = in_addr_prefix_to_string(address->family, &address->address, address->prefixlen, &addr);
-        if (r < 0)
-                return r;
-
-        if (in_addr_is_set(address->family, &address->peer)) {
-                r = in_addr_to_string(address->family, &address->peer, &peer);
-                if (r < 0)
-                        return r;
-        }
-
         fprintf(f,
                 "\n[Address]\n"
                 "Address=%s\n",
-                addr);
-
-        if (peer)
-                fprintf(f, "Peer=%s\n", peer);
-
+                IN_ADDR_PREFIX_TO_STRING(address->family, &address->address, address->prefixlen));
+        if (in_addr_is_set(address->family, &address->peer))
+                fprintf(f, "Peer=%s\n",
+                        IN_ADDR_TO_STRING(address->family, &address->peer));
         return 0;
 }
 
 static int route_dump(Route *route, FILE *f) {
-        _cleanup_free_ char *dest = NULL, *gateway = NULL;
-        int r;
-
-        if (in_addr_is_set(route->family, &route->dest)) {
-                r = in_addr_prefix_to_string(route->family, &route->dest, route->prefixlen, &dest);
-                if (r < 0)
-                        return r;
-        }
-
-        r = in_addr_to_string(route->family, &route->gateway, &gateway);
-        if (r < 0)
-                return r;
-
         fputs("\n[Route]\n", f);
-        if (dest)
-                fprintf(f, "Destination=%s\n", dest);
-        fprintf(f, "Gateway=%s\n", gateway);
+        if (in_addr_is_set(route->family, &route->dest))
+                fprintf(f, "Destination=%s\n",
+                        IN_ADDR_PREFIX_TO_STRING(route->family, &route->dest, route->prefixlen));
+        fprintf(f, "Gateway=%s\n",
+                IN_ADDR_TO_STRING(route->family, &route->gateway));
 
         return 0;
 }