[Spice-devel] [PATCH spice-server 2/3] red-channel: Avoid possible invalid function pointer type cast
Frediano Ziglio
fziglio at redhat.com
Sun May 6 11:10:32 UTC 2018
Avoid casting function pointer with different argument providing
a proper utility instead.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/red-channel.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/server/red-channel.c b/server/red-channel.c
index ad45fb52..1b38f04d 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -301,10 +301,19 @@ red_channel_init(RedChannel *self)
self->priv->client_cbs.migrate = red_channel_client_default_migrate;
}
+// utility to avoid possible invalid function cast
+static void
+red_channel_foreach_client(RedChannel *channel, void (*func)(RedChannelClient* client))
+{
+ RedChannelClient *client;
+ GLIST_FOREACH(channel->priv->clients, RedChannelClient, client) {
+ func(client);
+ }
+}
void red_channel_receive(RedChannel *channel)
{
- g_list_foreach(channel->priv->clients, (GFunc)red_channel_client_receive, NULL);
+ red_channel_foreach_client(channel, red_channel_client_receive);
}
void red_channel_add_client(RedChannel *channel, RedChannelClient *rcc)
@@ -403,13 +412,13 @@ void red_channel_destroy(RedChannel *channel)
// prevent future connection
reds_unregister_channel(channel->priv->reds, channel);
- g_list_foreach(channel->priv->clients, (GFunc)red_channel_client_destroy, NULL);
+ red_channel_foreach_client(channel, red_channel_client_destroy);
g_object_unref(channel);
}
void red_channel_send(RedChannel *channel)
{
- g_list_foreach(channel->priv->clients, (GFunc)red_channel_client_send, NULL);
+ red_channel_foreach_client(channel, red_channel_client_send);
}
void red_channel_push(RedChannel *channel)
@@ -418,7 +427,7 @@ void red_channel_push(RedChannel *channel)
return;
}
- g_list_foreach(channel->priv->clients, (GFunc)red_channel_client_push, NULL);
+ red_channel_foreach_client(channel, red_channel_client_push);
}
void red_channel_pipes_add(RedChannel *channel, RedPipeItem *item)
@@ -478,7 +487,7 @@ void red_channel_remove_client(RedChannel *channel, RedChannelClient *rcc)
void red_channel_disconnect(RedChannel *channel)
{
- g_list_foreach(channel->priv->clients, (GFunc)red_channel_client_disconnect, NULL);
+ red_channel_foreach_client(channel, red_channel_client_disconnect);
}
void red_channel_connect(RedChannel *channel, RedClient *client,
--
2.17.0
More information about the Spice-devel
mailing list