From: Holger Schemel Date: Mon, 7 Jan 2019 15:42:30 +0000 (+0100) Subject: fixed potential crash bug (accessing invalid memory) X-Git-Tag: 4.1.2.0~60 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=636dfa7f332268725c5377a7bca40f1ad83ad484 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. --- 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); }