]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
unit: make UNIT() cast function deal with NULL pointers
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Nov 2018 08:33:31 +0000 (09:33 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 8 Nov 2018 09:47:08 +0000 (10:47 +0100)
Fixes: #10681
src/core/unit.h

index b6ef9d97ee6104dbca0c9afdb6b402375d9c7e0f..c91fb49c609cc68864eb710ac72187ffd7f37d4e 100644 (file)
@@ -582,7 +582,12 @@ extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX];
         }
 
 /* For casting the various unit types into a unit */
-#define UNIT(u) (&(u)->meta)
+#define UNIT(u)                                         \
+        ({                                              \
+                typeof(u) _u_ = (u);                    \
+                Unit *_w_ = _u_ ? &(_u_)->meta : NULL;  \
+                _w_;                                    \
+        })
 
 #define UNIT_HAS_EXEC_CONTEXT(u) (UNIT_VTABLE(u)->exec_context_offset > 0)
 #define UNIT_HAS_CGROUP_CONTEXT(u) (UNIT_VTABLE(u)->cgroup_context_offset > 0)