From 636dfa7f332268725c5377a7bca40f1ad83ad484 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 7 Jan 2019 16:42:30 +0100 Subject: [PATCH] fixed potential crash bug (accessing invalid memory) This change fixes a bug that occured when invoking the changed function with a "graphic" parameter indicating undefined graphic, which is defined as "-1" and caused an "array out of bounds" access. To fix this bug, the function parameter is checked before used. --- src/tools.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools.c b/src/tools.c index 459f85a7..33b67795 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1150,10 +1150,12 @@ void FadeSkipNextFadeOut(void) static Bitmap *getBitmapFromGraphicOrDefault(int graphic, int default_graphic) { + if (graphic == IMG_UNDEFINED) + return NULL; + boolean redefined = getImageListEntryFromImageID(graphic)->redefined; - return (graphic == IMG_UNDEFINED ? NULL : - graphic_info[graphic].bitmap != NULL || redefined ? + return (graphic_info[graphic].bitmap != NULL || redefined ? graphic_info[graphic].bitmap : graphic_info[default_graphic].bitmap); } -- 2.34.1