[Spice-devel] spice-gtk: Fix error handling in stream_get_current_frame()

Francois Gouget fgouget at codeweavers.com
Fri Oct 30 04:17:30 PDT 2015


*data must always be set to NULL on error.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 src/channel-display.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/channel-display.c b/src/channel-display.c
index 46e9829..9e42dd9 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -1081,20 +1081,21 @@ uint32_t stream_get_current_frame(display_stream *st, uint8_t **data)
         return 0;
     }
 
-    if (spice_msg_in_type(st->msg_data) == SPICE_MSG_DISPLAY_STREAM_DATA) {
+    switch (spice_msg_in_type(st->msg_data)) {
+    case SPICE_MSG_DISPLAY_STREAM_DATA: {
         SpiceMsgDisplayStreamData *op = spice_msg_in_parsed(st->msg_data);
-
         *data = op->data;
         return op->data_size;
-    } else {
+    }
+    case SPICE_MSG_DISPLAY_STREAM_DATA_SIZED: {
         SpiceMsgDisplayStreamDataSized *op = spice_msg_in_parsed(st->msg_data);
-
-        g_return_val_if_fail(spice_msg_in_type(st->msg_data) ==
-                             SPICE_MSG_DISPLAY_STREAM_DATA_SIZED, 0);
         *data = op->data;
         return op->data_size;
-   }
-
+    }
+    default:
+        *data = NULL;
+        g_return_val_if_reached(0);
+    }
 }
 
 G_GNUC_INTERNAL
-- 
2.6.1


More information about the Spice-devel mailing list