[systemd-devel] [PATCH 2/7] bus: fix bus_message_read_strv

Lennart Poettering lennart at poettering.net
Thu Nov 7 09:50:26 PST 2013


On Thu, 07.11.13 13:48, Marc-Antoine Perennou (Marc-Antoine at Perennou.com) wrote:

> message_read_strv_extend returns 0 on success

Ah, hmm.

sd_bus_message_read_strv() was actually right,
bus_message_read_strv_extend() isn't!

The rule is: we return 0 when we hit the end of an array and 1 on
success. 

(If you read beyond the end of a message, a struct, a variant, and so on
we will generate an error, we only return 0 for end of *array*. This is
because arrays have variable sizes, so it makes sense to loop through
them until you reach the end. This is different for messages/structs and
so on where you really need to know what you read.)

> ---
>  src/libsystemd-bus/bus-message.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
> index 0fd9aa1..16b2201 100644
> --- a/src/libsystemd-bus/bus-message.c
> +++ b/src/libsystemd-bus/bus-message.c
> @@ -4438,7 +4438,7 @@ _public_ int sd_bus_message_read_strv(sd_bus_message *m, char ***l) {
>          assert_return(l, -EINVAL);
>  
>          r = bus_message_read_strv_extend(m, &strv);
> -        if (r <= 0) {
> +        if (r < 0) {
>                  strv_free(strv);
>                  return r;
>          }


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list