daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
21255d
From a11334f0eae67b5159a416193e2e37634281000a Mon Sep 17 00:00:00 2001
21255d
From: Lennart Poettering <lennart@poettering.net>
21255d
Date: Thu, 8 Nov 2018 09:33:31 +0100
21255d
Subject: [PATCH] unit: make UNIT() cast function deal with NULL pointers
21255d
21255d
Fixes: #10681
21255d
(cherry picked from commit bbf11206230d1b089118971f98a047151cb5c4fa)
21255d
21255d
Related: #1871827
21255d
---
21255d
 src/core/unit.h | 7 ++++++-
21255d
 1 file changed, 6 insertions(+), 1 deletion(-)
21255d
21255d
diff --git a/src/core/unit.h b/src/core/unit.h
21255d
index 6e37fd6f5a..ec45b5fb48 100644
21255d
--- a/src/core/unit.h
21255d
+++ b/src/core/unit.h
21255d
@@ -597,7 +597,12 @@ extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX];
21255d
         }
21255d
 
21255d
 /* For casting the various unit types into a unit */
21255d
-#define UNIT(u) (&(u)->meta)
21255d
+#define UNIT(u)                                         \
21255d
+        ({                                              \
21255d
+                typeof(u) _u_ = (u);                    \
21255d
+                Unit *_w_ = _u_ ? &(_u_)->meta : NULL;  \
21255d
+                _w_;                                    \
21255d
+        })
21255d
 
21255d
 #define UNIT_HAS_EXEC_CONTEXT(u) (UNIT_VTABLE(u)->exec_context_offset > 0)
21255d
 #define UNIT_HAS_CGROUP_CONTEXT(u) (UNIT_VTABLE(u)->cgroup_context_offset > 0)