[Spice-devel] [PATCH spice-server 3/3] char-device: Avoid possible invalid function pointer cast

Jonathon Jongsma jjongsma at redhat.com
Thu May 10 16:25:59 UTC 2018


On Sun, 2018-05-06 at 12:10 +0100, Frediano Ziglio wrote:
> This is reported by GCC 8.0.1 (Fedora 28).
> Instead of doing a possible invalid cast destroy and create the
> queue again.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/char-device.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/server/char-device.c b/server/char-device.c
> index 242d8782..aef6e887 100644
> --- a/server/char-device.c
> +++ b/server/char-device.c
> @@ -835,8 +835,8 @@ void red_char_device_reset(RedCharDevice *dev)
>  
>          spice_debug("send_queue_empty %d",
> g_queue_is_empty(dev_client->send_queue));
>          dev_client->num_send_tokens +=
> g_queue_get_length(dev_client->send_queue);
> -        g_queue_foreach(dev_client->send_queue,
> (GFunc)red_pipe_item_unref, NULL);
> -        g_queue_clear(dev_client->send_queue);
> +        g_queue_free_full(dev_client->send_queue,
> (GDestroyNotify)red_pipe_item_unref);

gcc 8.x doesn't complain about this function cast? GDestroyNotify and
red_pipe_item_unref() have different argument types (void* vs.
RedPipeItem*). Is gcc fine since there are the same number of arguments
and they're both pointer types? 


> +        dev_client->send_queue = g_queue_new();
>  
>          /* If device is reset, we must reset the tokens counters as
> well as we
>           * don't hold any data from client and upon agent's
> reconnection we send

Assuming that gcc is happy with the above cast:

Acked-by: Jonathon Jongsma <jjongsma at redhat.com>


More information about the Spice-devel mailing list