]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: check for NULLs in more places
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 4 Dec 2021 11:11:31 +0000 (12:11 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 5 Dec 2021 23:50:53 +0000 (08:50 +0900)
Fixes issues pointed out by the `cpp/inconsistent-null-check` LGTM
query.

src/core/automount.c
src/core/device.c
src/core/mount.c
src/core/swap.c
src/network/netdev/macsec.c
src/network/networkd-network.c
src/resolve/resolved-dns-scope.c

index 02089aed4e4966d02e38d52e83d4075a4d4c058d..70dbbb637d683e7bded45570760555fdbc2d2e25 100644 (file)
@@ -69,6 +69,7 @@ static int automount_send_ready(Automount *a, Set *tokens, int status);
 static void automount_init(Unit *u) {
         Automount *a = AUTOMOUNT(u);
 
+        assert(a);
         assert(u);
         assert(u->load_state == UNIT_STUB);
 
index 66841984feab5fd42e0c359805349cefd479a340..43f49573b9115e2c813d38931cf64a230dea7963 100644 (file)
@@ -248,6 +248,7 @@ static int device_serialize(Unit *u, FILE *f, FDSet *fds) {
         _cleanup_free_ char *s = NULL;
         Device *d = DEVICE(u);
 
+        assert(d);
         assert(u);
         assert(f);
         assert(fds);
@@ -264,6 +265,7 @@ static int device_deserialize_item(Unit *u, const char *key, const char *value,
         Device *d = DEVICE(u);
         int r;
 
+        assert(d);
         assert(u);
         assert(key);
         assert(value);
index 35368fe8e682b7fef8628cc008eaeaf37cd191de..fcff70d40b576d640533e11eeeaa1d3a9a54bf57 100644 (file)
@@ -179,6 +179,7 @@ static bool mount_needs_quota(const MountParameters *p) {
 static void mount_init(Unit *u) {
         Mount *m = MOUNT(u);
 
+        assert(m);
         assert(u);
         assert(u->load_state == UNIT_STUB);
 
@@ -681,6 +682,7 @@ static int mount_load(Unit *u) {
         Mount *m = MOUNT(u);
         int r, q = 0;
 
+        assert(m);
         assert(u);
         assert(u->load_state == UNIT_STUB);
 
@@ -1256,6 +1258,7 @@ static int mount_deserialize_item(Unit *u, const char *key, const char *value, F
         Mount *m = MOUNT(u);
         int r;
 
+        assert(m);
         assert(u);
         assert(key);
         assert(value);
@@ -1794,6 +1797,9 @@ static int mount_get_timeout(Unit *u, usec_t *timeout) {
         usec_t t;
         int r;
 
+        assert(m);
+        assert(u);
+
         if (!m->timer_event_source)
                 return 0;
 
index 3b28235194d27a7bc8b724e1c5330d19ac3e5203..9c0d4fb2277e04bc0601ab20f6ff1df2cc4fd0b4 100644 (file)
@@ -1220,6 +1220,8 @@ static int swap_process_proc_swaps(Manager *m) {
                 LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_SWAP]) {
                         Swap *swap = SWAP(u);
 
+                        assert(swap);
+
                         swap->is_active = swap->just_activated = false;
                 }
 
@@ -1231,6 +1233,8 @@ static int swap_process_proc_swaps(Manager *m) {
         LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_SWAP]) {
                 Swap *swap = SWAP(u);
 
+                assert(swap);
+
                 if (!swap->is_active) {
 
                         swap_unset_proc_swaps(swap);
@@ -1495,6 +1499,9 @@ static int swap_get_timeout(Unit *u, usec_t *timeout) {
         usec_t t;
         int r;
 
+        assert(s);
+        assert(u);
+
         if (!s->timer_event_source)
                 return 0;
 
index 72689742fb1ca0de38159fec8b31a8f64c263691..f1a566a9ca6ec0cae433ccbd33e3df1d63856ff1 100644 (file)
@@ -511,6 +511,8 @@ static int netdev_macsec_fill_message_create(NetDev *netdev, Link *link, sd_netl
 
         v = MACSEC(netdev);
 
+        assert(v);
+
         if (v->port > 0) {
                 r = sd_netlink_message_append_u16(m, IFLA_MACSEC_PORT, v->port);
                 if (r < 0)
index 6651c6c04ccf610e459bc74059f00840da8a45fe..d551b23531bf20ce8a1dd1c9d78f23139268d857 100644 (file)
@@ -214,6 +214,8 @@ int network_verify(Network *network) {
                                 else
                                         continue;
 
+                                assert(m);
+
                                 if (m->mode == NETDEV_MACVLAN_MODE_PASSTHRU)
                                         network->link_local = ADDRESS_FAMILY_NO;
 
index 26a3006a6c98e72dbbb78f547d72d291787f9f6f..c0f6df6447c69fa9a53104514b04aa98ed4ff9ed 100644 (file)
@@ -1452,6 +1452,8 @@ int dns_scope_announce(DnsScope *scope, bool goodbye) {
 
                 rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_PTR,
                                                   "_services._dns-sd._udp.local");
+                if (!rr)
+                        return log_oom();
                 rr->ptr.name = strdup(service_type);
                 rr->ttl = MDNS_DEFAULT_TTL;