Hi Jaakko,

On ke, 2015-07-15 at 11:35 +0300, Jaakko Hannikainen wrote:
> This helper function takes in a heap-allocated buffer of heap-allocated
> strings. If no strings should be removed, return the buffer. Else, free
> all empty strings, place nonempty strings to a new container and return
> it, freeing the old container.
> ---
>  src/service.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/src/service.c b/src/service.c
> index 2d8245e..1723586 100644
> --- a/src/service.c
> +++ b/src/service.c
> @@ -2926,6 +2926,38 @@ static DBusMessage *get_properties(DBusConnection 
> *conn,
>       return reply;
>  }
>  
> +static char **remove_empty_strings(char **strv)
> +{
> +     int amount, length, index;
> +     char **iter, **out;
> +
> +     amount = 0;
> +     length = g_strv_length(strv);

We could remove the call to g_strv_length() and calculate the max length
in the while loop below.

> +     iter = strv;
> +
> +     while (*iter)
> +             if (strlen(*iter++))
> +                     amount++;
> +
> +     if (amount == length - 1)
> +             return strv;
> +
> +     out = g_new0(char *, amount+1);
> +     index = 0;
> +     iter = strv;
> +
> +     while (*iter) {
> +             if (strlen(*iter))
> +                     out[index++] = *iter;
> +             else
> +                     g_free(*iter);
> +             iter++;
> +     }
> +
> +     g_free(strv);
> +     return out;
> +}
> +
>  static int update_proxy_configuration(struct connman_service *service,
>                               DBusMessageIter *array)
>  {


Cheers,
Jukka


_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman

Reply via email to