From da21875dc5a917d14c8903304d237610e5714ef0 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Mon, 7 Aug 2017 16:38:00 +0200 Subject: [PATCH] GVariant: fix for not having offset for empty arrays GVariant requires offsets for variable length struct members. Empty variable-size arrays which are at the beginning of a struct have offset 0. However, 0 was used as the indicator that there should be no offset added. This patch changes 0 to the impossible value. Change-Id: Icbc18e87831a20727f142a1218e6736e76bcce82 Signed-off-by: INSUN PYO --- dbus/dbus-marshal-gvariant.c | 8 ++++---- dbus/dbus-marshal-gvariant.h | 2 ++ dbus/dbus-marshal-recursive.c | 2 +- dbus/dbus-message.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dbus/dbus-marshal-gvariant.c b/dbus/dbus-marshal-gvariant.c index d6a3254..825b718 100644 --- a/dbus/dbus-marshal-gvariant.c +++ b/dbus/dbus-marshal-gvariant.c @@ -1205,7 +1205,7 @@ _dbus_writer_gvariant_add_offset_with_variability (DBusTypeWriter *writer, { check_offsets_in_body_for_adding (writer); - if (*writer->u.root.last_offset != 0) + if (*writer->u.root.last_offset != GVARIANT_LAST_OFFSET_NOT_SET) { write_offset (writer->value_str, *writer->u.root.last_offset, @@ -1215,14 +1215,14 @@ _dbus_writer_gvariant_add_offset_with_variability (DBusTypeWriter *writer, if (!fixed) *writer->u.root.last_offset = writer->value_pos - writer->value_start; else - *writer->u.root.last_offset = 0; + *writer->u.root.last_offset = GVARIANT_LAST_OFFSET_NOT_SET; } else if (DBUS_TYPE_STRUCT == writer->container_type || DBUS_TYPE_DICT_ENTRY == writer->container_type) { check_offsets_for_adding (writer); - if (writer->u.struct_or_dict.last_offset != 0) + if (writer->u.struct_or_dict.last_offset != GVARIANT_LAST_OFFSET_NOT_SET) { prepend_offset (writer->offsets, writer->u.struct_or_dict.last_offset, @@ -1231,7 +1231,7 @@ _dbus_writer_gvariant_add_offset_with_variability (DBusTypeWriter *writer, if (!fixed) writer->u.struct_or_dict.last_offset = writer->value_pos - writer->value_start; else - writer->u.struct_or_dict.last_offset = 0; + writer->u.struct_or_dict.last_offset = GVARIANT_LAST_OFFSET_NOT_SET; } else if (DBUS_TYPE_ARRAY == writer->container_type) { diff --git a/dbus/dbus-marshal-gvariant.h b/dbus/dbus-marshal-gvariant.h index 6802ace..07da4da 100644 --- a/dbus/dbus-marshal-gvariant.h +++ b/dbus/dbus-marshal-gvariant.h @@ -31,6 +31,8 @@ const DBusString *_dbus_get_gvariant_header_signature_str (void); +#define GVARIANT_LAST_OFFSET_NOT_SET ((size_t)-1) + dbus_bool_t _dbus_header_gvariant_create (DBusHeader *header, int byte_order, int type, diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index 183afb4..af027ed 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -2015,7 +2015,7 @@ writer_recurse_struct_or_dict_entry (DBusTypeWriter *writer, if (NULL == sub->value_str || !_dbus_string_init (sub->value_str)) return FALSE; sub->value_start = sub->value_pos = 0; - sub->u.struct_or_dict.last_offset = 0; + sub->u.struct_or_dict.last_offset = GVARIANT_LAST_OFFSET_NOT_SET; sub->offsets_size = 1; sub->is_fixed = TRUE; sub->offsets = dbus_new (DBusString, 1); diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 4a1f794..322155a 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -1403,7 +1403,7 @@ dbus_message_new_empty_header (dbus_bool_t gvariant) message->signature = NULL; message->unique_sender = NULL; - message->gvariant_body_last_offset = 0; + message->gvariant_body_last_offset = GVARIANT_LAST_OFFSET_NOT_SET; message->gvariant_body_last_pos = 0; return message; -- 2.7.4