[Spice-devel] [PATCH] pass proper type to SPICE_CONTAINEROF

Frediano Ziglio fziglio at redhat.com
Thu Dec 3 07:53:12 PST 2015


In some case the member specified to SPICE_CONTAINEROF was not
exactly the same type of the pointer passed.
This can cause issues if structure changes so use proper member.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/display-channel.c | 2 +-
 server/snd_worker.c      | 2 +-
 server/tree.c            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)


This patch fixes compilation errors if SPICE_CONTAINEROF check
the type of the pointer.


diff --git a/server/display-channel.c b/server/display-channel.c
index 7017b2a..c70694a 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -429,7 +429,7 @@ static void current_remove(DisplayChannel *display, TreeItem *item)
         RingItem *ring_item;
 
         if (now->type == TREE_ITEM_TYPE_DRAWABLE) {
-            Drawable *drawable = SPICE_CONTAINEROF(now, Drawable, tree_item);
+            Drawable *drawable = SPICE_CONTAINEROF(now, Drawable, tree_item.base);
             ring_item = now->siblings_link.prev;
             drawable_remove_from_pipes(drawable);
             current_remove_drawable(display, drawable);
diff --git a/server/snd_worker.c b/server/snd_worker.c
index b039939..1b9bad5 100644
--- a/server/snd_worker.c
+++ b/server/snd_worker.c
@@ -1102,7 +1102,7 @@ SPICE_GNUC_VISIBLE void spice_server_playback_put_samples(SpicePlaybackInstance
     PlaybackChannel *playback_channel;
     AudioFrame *frame;
 
-    frame = SPICE_CONTAINEROF(samples, AudioFrame, samples);
+    frame = SPICE_CONTAINEROF(samples, AudioFrame, samples[0]);
     playback_channel = frame->channel;
     spice_assert(playback_channel);
     if (!snd_channel_put(&playback_channel->base) ||
diff --git a/server/tree.c b/server/tree.c
index a3dfbde..9723284 100644
--- a/server/tree.c
+++ b/server/tree.c
@@ -129,7 +129,7 @@ static void dump_item(TreeItem *item, void *data)
 
     switch (item->type) {
     case TREE_ITEM_TYPE_DRAWABLE: {
-        Drawable *drawable = SPICE_CONTAINEROF(item, Drawable, tree_item);
+        Drawable *drawable = SPICE_CONTAINEROF(item, Drawable, tree_item.base);
         const int max_indent = 200;
         char indent_str[max_indent + 1];
         int indent_str_len;
-- 
2.4.3



More information about the Spice-devel mailing list