[systemd-devel] [PATCH 2/2] kdbus-test: fix kdbus item alignment in kdbus_hello_registrar()

Djalal Harouni tixxdz at opendz.org
Wed Jun 11 09:27:59 PDT 2014


Currently running the test-kdbus-activator test will fail with -EINVAL

To fix this, remove the redundant offsetof() macros since it is already
handled. The KDBUS_ITEM_SIZE() will expand into KDBUS_ITEM_HEADER_SIZE()
which expands into an offsetof() one.

Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
 test/kdbus-util.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/test/kdbus-util.c b/test/kdbus-util.c
index 5316263..7a6f272 100644
--- a/test/kdbus-util.c
+++ b/test/kdbus-util.c
@@ -117,20 +117,19 @@ kdbus_hello_registrar(const char *path, const char *name,
 	struct kdbus_item *item, *items;
 	size_t i, size;
 
-	size = KDBUS_ITEM_SIZE(offsetof(struct kdbus_item, str) + strlen(name) + 1)
-		+ num_access * KDBUS_ITEM_SIZE(offsetof(struct kdbus_item, policy_access) +
-					       sizeof(struct kdbus_policy_access));
+	size = KDBUS_ITEM_SIZE(strlen(name) + 1)
+		+ num_access * KDBUS_ITEM_SIZE(sizeof(struct kdbus_policy_access));
 
 	items = alloca(size);
 
 	item = items;
-	item->size = offsetof(struct kdbus_item, str) + strlen(name) + 1;
+	item->size = KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1;
 	item->type = KDBUS_ITEM_NAME;
 	strcpy(item->str, name);
 	item = KDBUS_ITEM_NEXT(item);
 
 	for (i = 0; i < num_access; i++) {
-		item->size = offsetof(struct kdbus_item, policy_access) +
+		item->size = KDBUS_ITEM_HEADER_SIZE +
 			     sizeof(struct kdbus_policy_access);
 		item->type = KDBUS_ITEM_POLICY_ACCESS;
 
-- 
1.9.0



More information about the systemd-devel mailing list