item: make kdbus_items_get_str() work with KDBUS_ITEM_NAME_{ADD,REMOVE,CHANGE}
authorDaniel Mack <daniel@zonque.org>
Wed, 1 Oct 2014 09:43:11 +0000 (11:43 +0200)
committerDaniel Mack <daniel@zonque.org>
Wed, 1 Oct 2014 09:43:11 +0000 (11:43 +0200)
KDBUS_ITEM_NAME_{ADD,REMOVE,CHANGE} embed their string in
item->name_change.name, not item->str. Handle that case.

Signed-off-by: Daniel Mack <daniel@zonque.org>
item.c

diff --git a/item.c b/item.c
index abcd1ada55673a5f3432e5aa85b132dce9991bcc..f0fe14523c7cb2982b325f5a1f1074084a2eb293 100644 (file)
--- a/item.c
+++ b/item.c
@@ -227,7 +227,7 @@ int kdbus_items_validate(const struct kdbus_item *items, size_t items_size)
  *
  * This function walks a list of items and searches for items of type
  * @item_type. If it finds exactly one such item, @str_ret will be set to
- * the .str member of the item.
+ * the string member of the item.
  *
  * Return: 0 if the item was found exactly once, -EEXIST if the item was
  * found more than once, and -EBADMSG if there was no item of the given type.
@@ -243,8 +243,21 @@ int kdbus_items_get_str(const struct kdbus_item *items, size_t items_size,
                        if (n)
                                return -EEXIST;
 
-                       n = item->str;
-                       continue;
+                       switch (item_type) {
+                       case KDBUS_ITEM_NAME_ADD:
+                       case KDBUS_ITEM_NAME_REMOVE:
+                       case KDBUS_ITEM_NAME_CHANGE:
+                               n = (const char *) &item->name_change.name;
+                               break;
+
+                       case KDBUS_ITEM_NAME:
+                       case KDBUS_ITEM_MAKE_NAME:
+                               n = item->str;
+                               break;
+
+                       default:
+                               break;
+                       }
                }
        }