From 031402e4bbe47a208b06f1245d01befbebc05ac6 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 13 Jun 2020 18:37:53 -0700 Subject: [PATCH] Fix indexing out-of-bounds with miscellaneous images This fixes indexing out-of-bounds in the functions that draw all the special images such as the elephant and teleporters. Let's make sure the game doesn't segfault. --- desktop_version/src/Graphics.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index b88e4647..4f9e979a 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -753,6 +753,10 @@ void Graphics::drawgui() void Graphics::drawimagecol( int t, int xp, int yp, int r = 0, int g = 0, int b = 0, bool cent/*= false*/ ) { + if (!INBOUNDS(t, images)) + { + return; + } SDL_Rect trect; if(r+g+b != 0) { @@ -784,6 +788,10 @@ void Graphics::drawimagecol( int t, int xp, int yp, int r = 0, int g = 0, int b void Graphics::drawimage( int t, int xp, int yp, bool cent/*=false*/ ) { + if (!INBOUNDS(t, images)) + { + return; + } SDL_Rect trect; if (cent) @@ -808,6 +816,11 @@ void Graphics::drawimage( int t, int xp, int yp, bool cent/*=false*/ ) void Graphics::drawpartimage( int t, int xp, int yp, int wp, int hp) { + if (!INBOUNDS(t, images)) + { + return; + } + SDL_Rect trect; trect.x = xp; @@ -2787,14 +2800,20 @@ void Graphics::drawtele(int x, int y, int t, int c) SDL_Rect telerect; setRect(telerect, x , y, tele_rect.w, tele_rect.h ); - BlitSurfaceColoured(tele[0], NULL, backBuffer, &telerect, ct); + if (INBOUNDS(0, tele)) + { + BlitSurfaceColoured(tele[0], NULL, backBuffer, &telerect, ct); + } setcol(c); if (t > 9) t = 8; if (t < 0) t = 0; setRect(telerect, x , y, tele_rect.w, tele_rect.h ); - BlitSurfaceColoured(tele[t], NULL, backBuffer, &telerect, ct); + if (INBOUNDS(t, tele)) + { + BlitSurfaceColoured(tele[t], NULL, backBuffer, &telerect, ct); + } } Uint32 Graphics::getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a)