[Spice-devel,client,v3,1/4] streaming: Check the stream id in display_update_stream_report() too

Submitted by Francois Gouget on Aug. 11, 2016, 10:20 a.m.

Details

Message ID a093d737e6eed4f3a6e301e4ba7bef4c85782260.1470910527.git.fgouget@free.fr
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Francois Gouget Aug. 11, 2016, 10:20 a.m.
It's safer and more consistent than assuming the caller has done the
check already.

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

Patch hide | download patch | download mbox

diff --git a/src/channel-display.c b/src/channel-display.c
index cf9c583..b4c9ec0 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -1222,9 +1222,16 @@  void stream_display_frame(display_stream *st, SpiceMsgIn *frame_msg,
 static void display_update_stream_report(SpiceDisplayChannel *channel, uint32_t stream_id,
                                          uint32_t frame_time, int32_t latency)
 {
-    display_stream *st = channel->priv->streams[stream_id];
+    SpiceDisplayChannelPrivate *c = channel->priv;
+    display_stream *st;
     guint64 now;
 
+    g_return_if_fail(c != NULL);
+    g_return_if_fail(c->streams != NULL);
+    g_return_if_fail(c->nstreams > stream_id);
+
+    st = channel->priv->streams[stream_id];
+
     if (!st->report_is_active) {
         return;
     }

Comments

> 
> It's safer and more consistent than assuming the caller has done the
> check already.
> 
> Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  src/channel-display.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/channel-display.c b/src/channel-display.c
> index cf9c583..b4c9ec0 100644
> --- a/src/channel-display.c
> +++ b/src/channel-display.c
> @@ -1222,9 +1222,16 @@ void stream_display_frame(display_stream *st,
> SpiceMsgIn *frame_msg,
>  static void display_update_stream_report(SpiceDisplayChannel *channel,
>  uint32_t stream_id,
>                                           uint32_t frame_time, int32_t
>                                           latency)
>  {
> -    display_stream *st = channel->priv->streams[stream_id];
> +    SpiceDisplayChannelPrivate *c = channel->priv;
> +    display_stream *st;
>      guint64 now;
>  
> +    g_return_if_fail(c != NULL);
> +    g_return_if_fail(c->streams != NULL);
> +    g_return_if_fail(c->nstreams > stream_id);
> +
> +    st = channel->priv->streams[stream_id];
> +
>      if (!st->report_is_active) {
>          return;
>      }