gvariant: handle immediate iteration with empty body 42/175942/1 accepted/tizen/unified/20180418.143529 submit/tizen/20180418.024038 submit/tizen/20180420.022505
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 13 Apr 2018 14:07:53 +0000 (16:07 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 13 Apr 2018 14:18:55 +0000 (16:18 +0200)
commit7268f75a10e4078a0c8d53658ec060beb0ac769d
tree29082c4a9aba9ee1d4964fe1256935eca6a60382
parent89fb5a0c39eeec601950444aa1abdcfe2950d36b
gvariant: handle immediate iteration with empty body

With GVariant, we had to do a trade-off. libdbus API does not provide
any function that would state that a message is "finished".
While creating dbus-1 messages, they are always complete.
On additions header fields can change, and all the data is simply
appended. With GVariant it is different. The format does not have
signature field anymore in the header, but it is at the end
of a message, as a part of body variant. After a body variant,
there is also a body offset appended. These values are added to a body
when a message is considered "finished". We have chosen function
dbus_message_lock() as a signal that a message is finished.
This function is always called when a message is added to output queue.

Now, what does actually happen in case of immediate iteration after
creating a message with empty body? The length of the body is zero.
This is not possible for valid GVariant as it has at least one NUL byte,
signature (minimal is '()') and a body offset. It breaks
_dbus_message_gvariant_get_body_length(). However, it can be done with
public interface, therefore this patch:

1. fixes _dbus_message_gvariant_get_body_length() to return 0 in case
of empty body, instead of computing "negative" value.
2. warns users when they try to iterate over a GVariant message
that is not locked.

Change-Id: Ie7dc331f5ea278502df02a976e555a2c7d249197
dbus/dbus-marshal-gvariant.c