diff mbox series

sdl: Move use of surface pointer below check for whether it is NULL

Message ID 20180515185814.1374-1-peter.maydell@linaro.org
State Superseded
Headers show
Series sdl: Move use of surface pointer below check for whether it is NULL | expand

Commit Message

Peter Maydell May 15, 2018, 6:58 p.m. UTC
In commit 2ab858c6c38ee1 we added a use of the 'surf' variable
in sdl2_2d_update() that was unfortunately placed above the
early-exit-if-NULL check. Move it to where it ought to be.

Fixes: Coverity CID 1390598
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 ui/sdl2-2d.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

-- 
2.17.0

Comments

Philippe Mathieu-Daudé May 15, 2018, 8:51 p.m. UTC | #1
On 05/15/2018 03:58 PM, Peter Maydell wrote:
> In commit 2ab858c6c38ee1 we added a use of the 'surf' variable

> in sdl2_2d_update() that was unfortunately placed above the

> early-exit-if-NULL check. Move it to where it ought to be.

> 

> Fixes: Coverity CID 1390598

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


> ---

>  ui/sdl2-2d.c | 6 +++---

>  1 file changed, 3 insertions(+), 3 deletions(-)

> 

> diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c

> index 1f34817bae..85484407be 100644

> --- a/ui/sdl2-2d.c

> +++ b/ui/sdl2-2d.c

> @@ -36,9 +36,7 @@ void sdl2_2d_update(DisplayChangeListener *dcl,

>      struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);

>      DisplaySurface *surf = qemu_console_surface(dcl->con);

>      SDL_Rect rect;

> -    size_t surface_data_offset = surface_bytes_per_pixel(surf) * x +

> -                                 surface_stride(surf) * y;

> -

> +    size_t surface_data_offset;

>      assert(!scon->opengl);

>  

>      if (!surf) {

> @@ -48,6 +46,8 @@ void sdl2_2d_update(DisplayChangeListener *dcl,

>          return;

>      }

>  

> +    surface_data_offset = surface_bytes_per_pixel(surf) * x +

> +                          surface_stride(surf) * y;

>      rect.x = x;

>      rect.y = y;

>      rect.w = w;

>
Gerd Hoffmann May 18, 2018, 7:04 a.m. UTC | #2
On Tue, May 15, 2018 at 07:58:14PM +0100, Peter Maydell wrote:
> In commit 2ab858c6c38ee1 we added a use of the 'surf' variable

> in sdl2_2d_update() that was unfortunately placed above the

> early-exit-if-NULL check. Move it to where it ought to be.


Added to ui patch queue.

thanks,
  Gerd
Anatoly Trosinenko May 18, 2018, 8:20 a.m. UTC | #3
Please excuse me and thank you very much for the fix!

2018-05-18 10:04 GMT+03:00 Gerd Hoffmann <kraxel@redhat.com>:

> On Tue, May 15, 2018 at 07:58:14PM +0100, Peter Maydell wrote:

> > In commit 2ab858c6c38ee1 we added a use of the 'surf' variable

> > in sdl2_2d_update() that was unfortunately placed above the

> > early-exit-if-NULL check. Move it to where it ought to be.

>

> Added to ui patch queue.

>

> thanks,

>   Gerd

>

>



-- 
Anatoly <anatoly.trosinenko@gmail.com>
<div dir="ltr">Please excuse me and thank you very much for the fix!<br><div class="gmail_extra"><br><div class="gmail_quote">2018-05-18 10:04 GMT+03:00 Gerd Hoffmann <span dir="ltr">&lt;<a href="mailto:kraxel@redhat.com" target="_blank">kraxel@redhat.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, May 15, 2018 at 07:58:14PM +0100, Peter Maydell wrote:<br>
&gt; In commit 2ab858c6c38ee1 we added a use of the &#39;surf&#39; variable<br>
&gt; in sdl2_2d_update() that was unfortunately placed above the<br>
&gt; early-exit-if-NULL check. Move it to where it ought to be.<br>
<br>
</span>Added to ui patch queue.<br>
<br>
thanks,<br>
  Gerd<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Anatoly<a href="mailto:anatoly.trosinenko@gmail.com" target="_blank"></a></div>
</div></div>
diff mbox series

Patch

diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c
index 1f34817bae..85484407be 100644
--- a/ui/sdl2-2d.c
+++ b/ui/sdl2-2d.c
@@ -36,9 +36,7 @@  void sdl2_2d_update(DisplayChangeListener *dcl,
     struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
     DisplaySurface *surf = qemu_console_surface(dcl->con);
     SDL_Rect rect;
-    size_t surface_data_offset = surface_bytes_per_pixel(surf) * x +
-                                 surface_stride(surf) * y;
-
+    size_t surface_data_offset;
     assert(!scon->opengl);
 
     if (!surf) {
@@ -48,6 +46,8 @@  void sdl2_2d_update(DisplayChangeListener *dcl,
         return;
     }
 
+    surface_data_offset = surface_bytes_per_pixel(surf) * x +
+                          surface_stride(surf) * y;
     rect.x = x;
     rect.y = y;
     rect.w = w;