[Spice-devel] [PATCH spice-gtk v3 4/7] spice-uri: Reset SpiceUri before parsing

Victor Toso lists at victortoso.com
Fri May 20 08:24:50 UTC 2016


Hi,

On Thu, May 19, 2016 at 06:38:06PM +0200, Pavel Grunt wrote:
> Avoid using old values after parsing a new uri.

A test case with re-using the SpiceURI could be handy

>
> Related: rhbz#1335239
> ---
>  src/spice-uri.c        | 7 +++++++
>  tests/test-spice-uri.c | 4 ++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/src/spice-uri.c b/src/spice-uri.c
> index 3bdb502..04ea3cb 100644
> --- a/src/spice-uri.c
> +++ b/src/spice-uri.c
> @@ -105,6 +105,13 @@ gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error)
>      size_t len;
>
>      g_return_val_if_fail(self != NULL, FALSE);
> +
> +    self->scheme = NULL;
> +    self->hostname = NULL;
> +    self->port = 0;
> +    self->user = NULL;
> +    self->password = NULL;
> +

g_clear_pointer to avoid leaks?

>      g_return_val_if_fail(_uri != NULL, FALSE);
>  
>      uri = dup = g_strdup(_uri);
> diff --git a/tests/test-spice-uri.c b/tests/test-spice-uri.c
> index e8cfcc9..1b14dbb 100644
> --- a/tests/test-spice-uri.c
> +++ b/tests/test-spice-uri.c
> @@ -36,10 +36,10 @@ static void test_spice_uri_ipv4(void)
>          {"http://127.0.0.1:port", "http", "127.0.0.1", 3128, NULL, NULL}, /* invalid port */
>      };
>      const struct test_case valid_test_cases[] = {
> -        {"http://127.0.0.1/", "http", "127.0.0.1", 3128, NULL, NULL},
> +        {"http://user:password@host:80", "http", "host", 80, "user", "password"},
> +        {"http://127.0.0.1/", "http", "127.0.0.1", 3128, NULL, NULL}, /* reset user & password */
>          {"https://127.0.0.1", "https", "127.0.0.1", 3129, NULL, NULL},
>          {"127.0.0.1", "http", "127.0.0.1", 3128, NULL, NULL},
> -        {"http://user:password@host:80", "http", "host", 80, "user", "password"},
>      };
>  
>      guint i;
> -- 
> 2.8.2
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list