[Spice-devel] [spice-gtk] Fix VD_AGENT_HAS_CAPABILITY use
Christophe Fergeau
cfergeau at redhat.com
Fri Sep 7 07:07:55 PDT 2012
The 'size' argument to this macro (defined in
spice-protocol/spice/vd_agent.h) is the number of 32 bit elements
available in its first argument. In channel-main.c it's used
most of the time with SpiceMainChannelPrivate::agent_caps which is
an uint32_t[VD_AGENT_CAPS_SIZE]. The 'size' argument to pass to
VD_AGENT_HAS_CAPABILITY is thus the number of elements in this array,
and not sizeof(agent_caps).
Fixes rhbz#837545
---
gtk/channel-main.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index ff9b0c1..a413ec4 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -1041,7 +1041,7 @@ static void agent_announce_caps(SpiceMainChannel *channel)
}
#define HAS_CLIPBOARD_SELECTION(c) \
- VD_AGENT_HAS_CAPABILITY((c)->agent_caps, sizeof((c)->agent_caps), VD_AGENT_CAP_CLIPBOARD_SELECTION)
+ VD_AGENT_HAS_CAPABILITY((c)->agent_caps, G_N_ELEMENTS((c)->agent_caps), VD_AGENT_CAP_CLIPBOARD_SELECTION)
/* any context: the message is not flushed immediately,
you can wakeup() the channel coroutine or send_msg_queue() */
@@ -1058,7 +1058,7 @@ static void agent_clipboard_grab(SpiceMainChannel *channel, guint selection,
return;
g_return_if_fail(VD_AGENT_HAS_CAPABILITY(c->agent_caps,
- sizeof(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
+ G_N_ELEMENTS(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
size = sizeof(VDAgentClipboardGrab) + sizeof(uint32_t) * ntypes;
if (HAS_CLIPBOARD_SELECTION(c))
@@ -1098,7 +1098,7 @@ static void agent_clipboard_notify(SpiceMainChannel *channel, guint selection,
g_return_if_fail(c->agent_connected);
g_return_if_fail(VD_AGENT_HAS_CAPABILITY(c->agent_caps,
- sizeof(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
+ G_N_ELEMENTS(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
msgsize = sizeof(VDAgentClipboard);
if (HAS_CLIPBOARD_SELECTION(c))
@@ -1134,7 +1134,7 @@ static void agent_clipboard_request(SpiceMainChannel *channel, guint selection,
g_return_if_fail(c->agent_connected);
g_return_if_fail(VD_AGENT_HAS_CAPABILITY(c->agent_caps,
- sizeof(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
+ G_N_ELEMENTS(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
msgsize = sizeof(VDAgentClipboardRequest);
if (HAS_CLIPBOARD_SELECTION(c))
@@ -1170,7 +1170,7 @@ static void agent_clipboard_release(SpiceMainChannel *channel, guint selection)
g_return_if_fail(c->agent_connected);
g_return_if_fail(VD_AGENT_HAS_CAPABILITY(c->agent_caps,
- sizeof(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
+ G_N_ELEMENTS(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
if (HAS_CLIPBOARD_SELECTION(c)) {
msg[0] = selection;
@@ -1398,7 +1398,7 @@ static void main_agent_handle_msg(SpiceChannel *channel,
case VD_AGENT_CLIPBOARD_REQUEST:
case VD_AGENT_CLIPBOARD_GRAB:
case VD_AGENT_CLIPBOARD:
- if (VD_AGENT_HAS_CAPABILITY(c->agent_caps, sizeof(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_SELECTION)) {
+ if (VD_AGENT_HAS_CAPABILITY(c->agent_caps, G_N_ELEMENTS(c->agent_caps), VD_AGENT_CAP_CLIPBOARD_SELECTION)) {
selection = *((guint8*)payload);
payload = ((guint8*)payload) + 4;
msg->size -= 4;
@@ -1431,7 +1431,7 @@ static void main_agent_handle_msg(SpiceChannel *channel,
if (caps->request)
agent_announce_caps(SPICE_MAIN_CHANNEL(channel));
- if (VD_AGENT_HAS_CAPABILITY(caps->caps, sizeof(c->agent_caps), VD_AGENT_CAP_DISPLAY_CONFIG) &&
+ if (VD_AGENT_HAS_CAPABILITY(caps->caps, G_N_ELEMENTS(c->agent_caps), VD_AGENT_CAP_DISPLAY_CONFIG) &&
!c->agent_display_config_sent) {
agent_display_config(SPICE_MAIN_CHANNEL(channel));
agent_send_msg_queue(SPICE_MAIN_CHANNEL(channel));
@@ -2021,7 +2021,7 @@ gboolean spice_main_agent_test_capability(SpiceMainChannel *channel, guint32 cap
if (!c->agent_caps_received)
return FALSE;
- return VD_AGENT_HAS_CAPABILITY(c->agent_caps, sizeof(c->agent_caps), cap);
+ return VD_AGENT_HAS_CAPABILITY(c->agent_caps, G_N_ELEMENTS(c->agent_caps), cap);
}
/**
--
1.7.11.4
More information about the Spice-devel
mailing list