anitazha / rpms / systemd

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