GVariant: fix for not having offset for empty arrays 05/142905/2 accepted/tizen/4.0/unified/20170828.222508 accepted/tizen/unified/20170808.171336 accepted/tizen/unified/20170811.021149 submit/tizen/20170808.013620 submit/tizen/20170810.123503 submit/tizen_4.0/20170828.100005
authorAdrian Szyndela <adrian.s@samsung.com>
Mon, 7 Aug 2017 14:38:00 +0000 (16:38 +0200)
committerINSUN PYO <insun.pyo@samsung.com>
Tue, 8 Aug 2017 01:12:31 +0000 (10:12 +0900)
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 <insun.pyo@samsung.com>
dbus/dbus-marshal-gvariant.c
dbus/dbus-marshal-gvariant.h
dbus/dbus-marshal-recursive.c
dbus/dbus-message.c

index d6a3254..825b718 100644 (file)
@@ -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)
   {
index 6802ace..07da4da 100644 (file)
@@ -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,
index 183afb4..af027ed 100644 (file)
@@ -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);
index 4a1f794..322155a 100644 (file)
@@ -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;