[PATCH spice-server] Avoid to access data before a NULL check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If you are testing for NULL data this means that variable could be
NULL so avoid to access before the check to make sure the check is hit.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/cursor-channel.c |  3 ++-
 server/dcc-send.c       | 11 ++++++++---
 server/stream.c         |  3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

Would not be easier to remove these checks?

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 63d6886d..5ece576c 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -182,11 +182,12 @@ static void cursor_pipe_item_free(RedPipeItem *base)
 static void red_marshall_cursor_init(CursorChannelClient *ccc, SpiceMarshaller *base_marshaller,
                                      RedPipeItem *pipe_item)
 {
+    spice_assert(ccc);
+
     CursorChannel *cursor_channel;
     RedChannelClient *rcc = RED_CHANNEL_CLIENT(ccc);
     SpiceMsgCursorInit msg;
 
-    spice_assert(rcc);
     cursor_channel = CURSOR_CHANNEL(red_channel_client_get_channel(rcc));
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_CURSOR_INIT);
diff --git a/server/dcc-send.c b/server/dcc-send.c
index 5a24e693..8e91b8fb 100644
--- a/server/dcc-send.c
+++ b/server/dcc-send.c
@@ -1922,8 +1922,8 @@ static void red_marshall_image(RedChannelClient *rcc,
                                SpiceMarshaller *m,
                                RedImageItem *item)
 {
-    DisplayChannelClient *dcc = DISPLAY_CHANNEL_CLIENT(rcc);
-    DisplayChannel *display = DCC_TO_DC(dcc);
+    DisplayChannelClient *dcc;
+    DisplayChannel *display;
     SpiceImage red_image;
     SpiceBitmap bitmap;
     SpiceChunks *chunks;
@@ -1932,7 +1932,12 @@ static void red_marshall_image(RedChannelClient *rcc,
     SpiceMarshaller *src_bitmap_out, *mask_bitmap_out;
     SpiceMarshaller *bitmap_palette_out, *lzplt_palette_out;
 
-    spice_assert(rcc && display && item);
+    spice_assert(rcc && item);
+
+    dcc = DISPLAY_CHANNEL_CLIENT(rcc);
+
+    display = DCC_TO_DC(dcc);
+    spice_assert(display);
 
     QXL_SET_IMAGE_ID(&red_image, QXL_IMAGE_GROUP_RED, display_channel_generate_uid(display));
     red_image.descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
diff --git a/server/stream.c b/server/stream.c
index f74a1385..0148d1ed 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -772,9 +772,10 @@ void stream_agent_stop(StreamAgent *agent)
 
 static void red_upgrade_item_free(RedPipeItem *base)
 {
+    g_return_if_fail(base != NULL);
+
     RedUpgradeItem *item = SPICE_UPCAST(RedUpgradeItem, base);
 
-    g_return_if_fail(item != NULL);
     g_return_if_fail(item->base.refcount == 0);
 
     drawable_unref(item->drawable);
-- 
2.13.5

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]