From d610e2dae3b9ddce7fd8843aff0c81fa1e016e98 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 30 Jun 2020 11:51:01 -0700 Subject: [PATCH] Add bounds checks to drawforetile/drawforetile2/drawforetile3 When I was writing the previous commit I noticed that these functions didn't have bounds checks, which is a bit bad. So I added them. --- desktop_version/src/Graphics.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 4bc043ab..70f87afc 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -3110,6 +3110,11 @@ void Graphics::setcolreal(Uint32 t) void Graphics::drawforetile(int x, int y, int t) { + if (!INBOUNDS(t, tiles)) + { + return; + } + SDL_Rect rect; setRect(rect, x,y,tiles_rect.w, tiles_rect.h); @@ -3128,6 +3133,11 @@ void Graphics::drawforetile(int x, int y, int t) void Graphics::drawforetile2(int x, int y, int t) { + if (!INBOUNDS(t, tiles2)) + { + return; + } + SDL_Rect rect; setRect(rect, x,y,tiles_rect.w, tiles_rect.h); @@ -3146,9 +3156,14 @@ void Graphics::drawforetile2(int x, int y, int t) void Graphics::drawforetile3(int x, int y, int t, int off) { + t += off * 30; + if (!INBOUNDS(t, tiles3)) + { + return; + } SDL_Rect rect; setRect(rect, x,y,tiles_rect.w, tiles_rect.h); - BlitSurfaceStandard(tiles3[t+(off*30)],NULL, foregroundBuffer, &rect ); + BlitSurfaceStandard(tiles3[t],NULL, foregroundBuffer, &rect ); } void Graphics::drawrect(int x, int y, int w, int h, int r, int g, int b)