host: deal with host/peer null pointers in debug messages
authorFelix Fietkau <nbd@nbd.name>
Tue, 23 Aug 2022 21:11:28 +0000 (23:11 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 23 Aug 2022 21:20:25 +0000 (23:20 +0200)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
host.h

diff --git a/host.h b/host.h
index bf61e75e9f4098c086a4a4375f5273339f5674ec..985ac4569e8f4361cbe8a4da7267e85840cf75fa 100644 (file)
--- a/host.h
+++ b/host.h
@@ -49,13 +49,20 @@ struct network_group {
 
 static inline const char *network_host_name(struct network_host *host)
 {
+       if (!host)
+               return "(none)";
+
        return host->node.key;
 }
 
 static inline const char *network_peer_name(struct network_peer *peer)
 {
-       struct network_host *host = container_of(peer, struct network_host, peer);
+       struct network_host *host;
+
+       if (!peer)
+               return "(none)";
 
+       host = container_of(peer, struct network_host, peer);
        return network_host_name(host);
 }