From: Lennart Poettering Date: Thu, 8 Nov 2018 08:33:31 +0000 (+0100) Subject: unit: make UNIT() cast function deal with NULL pointers X-Git-Tag: v240~384 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbf11206230d1b089118971f98a047151cb5c4fa;p=thirdparty%2Fsystemd.git unit: make UNIT() cast function deal with NULL pointers Fixes: #10681 --- diff --git a/src/core/unit.h b/src/core/unit.h index b6ef9d97ee6..c91fb49c609 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)