summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-08 09:33:31 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-08 10:47:08 +0100
commitbbf11206230d1b089118971f98a047151cb5c4fa (patch)
tree3ee325fb868dd8c1eb4efbf92721b4d019ffeb98 /src
parent8d2411f69348a081419c2fb7cddbe1970cf3eac5 (diff)
downloadsystemd-bbf11206230d1b089118971f98a047151cb5c4fa.tar.gz
systemd-bbf11206230d1b089118971f98a047151cb5c4fa.tar.bz2
systemd-bbf11206230d1b089118971f98a047151cb5c4fa.zip
unit: make UNIT() cast function deal with NULL pointers
Fixes: #10681
Diffstat (limited to 'src')
-rw-r--r--src/core/unit.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/core/unit.h b/src/core/unit.h
index b6ef9d97ee..c91fb49c60 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -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)