From e77fad5db8d32b67f543d178234c45ef1394eab4 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 17 May 2022 12:07:51 -0700 Subject: [PATCH] Fix potential NULL dereference of `images[t]` Without this, entering in-game and opening the map with missing graphics will result in a segfault. This is because even if the image doesn't exist, it's still pushed into the `images` std::vector as a NULL pointer. And it segfaults because we dereference it (to get things like their width and height). In contrast, passing them to SDL is fine because SDL always checks for NULL first. --- desktop_version/src/Graphics.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 87f10114..c340d8c6 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1103,7 +1103,7 @@ void Graphics::updatetextboxes(void) void Graphics::drawimagecol( int t, int xp, int yp, bool cent/*= false*/ ) { - if (!INBOUNDS_VEC(t, images)) + if (!INBOUNDS_VEC(t, images) || images[t] == NULL) { return; } @@ -1134,7 +1134,7 @@ void Graphics::drawimagecol( int t, int xp, int yp, bool cent/*= false*/ ) void Graphics::drawimage( int t, int xp, int yp, bool cent/*=false*/ ) { - if (!INBOUNDS_VEC(t, images)) + if (!INBOUNDS_VEC(t, images) || images[t] == NULL) { return; } @@ -1162,7 +1162,7 @@ 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_VEC(t, images)) + if (!INBOUNDS_VEC(t, images) || images[t] == NULL) { return; }